Have you ever sent a message in airplane mode… and it still appears instantly in your chat?
No loading. No delay. Just “sent”.
But in reality, there’s no internet.
So what’s actually happening under the hood?
Let’s break it down in a simple, system-design way.
✈️ A Simple Scenario: Sending a Message in Airplane Mode
Imagine this:
- You open your messaging app
- Turn on airplane mode
- Send a message
👉 The message appears instantly in your chat UI
But:
- It’s NOT delivered
- It’s NOT on the server
- The other person hasn’t received it
So how does it still feel real-time?
🤔 Why Messaging Apps Need Offline Support
Users expect messaging apps to:
- Work anytime (even without internet)
- Feel fast and responsive
- Never lose messages
Without offline support:
- Messages would fail immediately
- UX would feel broken
- Users would lose trust
👉 That’s why modern apps use offline-first architecture
💾 Local Storage & Message Persistence
When you send a message offline:
👉 The app stores it locally on your device
This could be:
- Local database (SQLite, Realm, etc.)
- In-app storage
The message is saved with:
- Content
- Timestamp
- Temporary ID
- Status (e.g., “pending”)
👉 This ensures:
- Messages don’t get lost
- UI can show them instantly
📥 Message Queueing on the Device
Offline messages are not forgotten.
They are added to a message queue.
Think of it like a waiting list:
[ Message 1 - Pending ]
[ Message 2 - Pending ]
[ Message 3 - Pending ]
👉 This queue ensures:
- Messages are sent in order
- Nothing is skipped
⚡ Why Messages Appear Instantly
Even without internet:
- The app writes the message to local storage
- Immediately updates the UI
👉 This creates the illusion of real-time messaging
The user sees the message instantly, even though it hasn’t been sent yet.
🔄 Syncing When Internet Returns
Once connectivity is back:
- App detects network availability
- Starts processing the queue
- Sends messages to the server
- Receives confirmation
👉 This process is called synchronization
📊 Delivery States Explained
Each message goes through states:
1. Sent
- Message stored locally
- Waiting to reach server
2. Delivered
- Server received message
- Sent to recipient device
3. Read
- Recipient opened the message
👉 These states update as sync happens
🖼️ Handling Media Uploads Offline
Text messages are easy.
Media (images, videos) are more complex:
- Files are stored locally
- Upload is delayed until internet is available
- App may show “upload pending”
👉 Some apps:
- Compress media first
- Retry uploads automatically
⚖️ Conflict Resolution & Message Ordering
What if things go wrong?
Example:
- Messages sent offline
- Messages received online
- Order mismatch
👉 Apps handle this using:
- Timestamps
- Unique message IDs
- Server-side ordering
This ensures:
- Messages appear in correct sequence
- No duplicates or confusion
🔁 Eventual Consistency (Simple Explanation)
Messaging apps don’t guarantee instant consistency.
Instead, they use:
👉 Eventual Consistency
Meaning:
- Data may not match instantly
- But will become correct over time
Example:
- You send a message offline
- It syncs later
- Eventually, both users see the same data
⚠️ Tradeoffs: Reliability vs Real-Time
Offline-first systems balance:
| Reliability | Real-time |
|---|---|
| Messages never lost | Slight delay possible |
| Works without internet | Sync needed later |
| Strong user trust | Not truly instant |
👉 Apps prioritize reliability over strict real-time
🚀 How Offline-First Improves UX
This approach makes apps feel:
- Fast (instant UI updates)
- Reliable (no data loss)
- Smooth (no errors on bad networks)
👉 Users don’t think about connectivity—they just use the app.
🔁 System Flow (Simple Mental Model)
Flow 1: Sending Message Offline
User → Local Storage → Message Queue → (Wait for Internet)
Flow 2: Sync After Reconnect
Queue → Server → Confirmation → Update Status
Flow 3: Message State Lifecycle
Sent → Delivered → Read
🎯 Key Takeaways
- Messages are stored locally first
- Offline messages go into a queue
- UI updates instantly for better UX
- Sync happens when internet returns
- Systems use eventual consistency
- Reliability is prioritized over real-time
📌 Conclusion
Offline support is what makes modern messaging apps feel seamless.
Even without internet, the system:
- Stores your actions
- Keeps everything in sync later
- Maintains a smooth user experience
👉 The magic isn’t real-time—it’s smart design