DEV Community

Cover image for How WhatsApp Works Without Internet: Offline Messaging and Sync Explained
SATYA SOOTAR
SATYA SOOTAR

Posted on

How WhatsApp Works Without Internet: Offline Messaging and Sync Explained

You're on the subway, signal drops to zero, and you still tap send on that message. A single grey tick appears. Your phone didn't throw an error, the app didn't crash, and somehow that message will reach your friend the moment you get back above ground. How does that actually work? Let's break it down.x

Why Messaging Apps Need Offline Support

Think about how you actually use your phone. You're in an elevator, on a flight, driving through a tunnel, or just in a building with terrible WiFi. Connectivity is not a constant, it's a privilege that comes and goes. If WhatsApp only worked when you had a perfect internet connection, it would be practically useless in the real world.

This is why modern messaging apps are built with what engineers call an offline-first architecture. The core idea is simple: the app should work as close to normal as possible even without internet, and quietly reconcile everything with the server the moment connection returns. The user should barely notice the difference.

What Actually Happens When You Hit Send Without Internet

Let's start with the simplest scenario: airplane mode.

You open WhatsApp, type "I'll be there in 10 minutes", and hit send. The app does not wait for a server response. It immediately displays your message in the chat with a single grey clock or tick icon. From your perspective the message is sent. But technically, it hasn't left your device yet.

What WhatsApp just did is write your message to local storage on your phone. It saved it as a pending item in a local queue, stamped it with a timestamp, assigned it a local ID, and tagged it with a status of "pending". The UI renders it immediately because it's reading from local storage, not from a server. That's why you see it instantly.

This pattern is called optimistic UI. The app assumes the best case scenario, shows you the result immediately, and handles the actual network operation in the background.

Flow diagram for wp messaging

Local Storage and Message Persistence

Your phone is running a tiny database. On Android, WhatsApp uses SQLite, a lightweight relational database that lives right on your device. On iOS it works similarly. Every message you send or receive gets stored in this local database, including messages you haven't sent yet.

This local database holds a lot more than just text. It stores the message content, who sent it, who it's going to, what time it was created, what its current delivery status is, and whether it's been queued for sending. Think of it like a local source of truth that the app reads from first before even thinking about the internet.

This is also why WhatsApp can show you your entire chat history even when you're completely offline. You're not loading messages from a server, you're reading from the database on your own device.

The Message Queue: Your Phone's Outbox

When a message is saved locally and there's no internet, it gets placed in what's called a message queue. This is basically an ordered list of things that need to be sent to the server when connectivity comes back.

The queue respects order. If you send three messages while offline, they go into the queue in sequence: message 1, message 2, message 3. When the internet returns, they get sent in that exact order. This matters because message ordering is something users care about deeply and it would be confusing if your messages arrived out of sequence.

The queue also handles retries. If the app tries to send a message and the connection drops mid-attempt, it doesn't give up. It retries with a strategy called exponential backoff, which means it waits a little, tries again, waits a bit longer, tries again, and so on. This prevents the app from hammering the server repeatedly and draining your battery.

flow 2

Syncing When You Come Back Online

This is where things get interesting. The moment your phone detects internet connectivity, a background process wakes up and starts the sync.

Here's roughly what happens:
First, the app works through the outgoing queue and uploads your pending messages to the WhatsApp server. Second, it asks the server if there are any incoming messages it missed while you were offline. The server has been holding those messages and delivers them now. Third, the local database gets updated with the new information and the UI refreshes to show everything.

This process of having multiple places store data (your phone and the server) and then reconciling them is called eventual consistency. You're not guaranteed that everyone sees the same state at the exact same millisecond. But you are guaranteed that eventually, once everyone is online, everything will be consistent. It's a deliberate tradeoff that prioritizes availability (the app keeps working offline) over perfect real-time accuracy.

Flow Diagram 3

Delivery States: What Those Ticks Actually Mean

This is probably the most visible part of the whole system and one most people are curious about.

One grey tick means the message has been saved on your device and sent to WhatsApp's server. The server has it. But it hasn't been delivered to your recipient's device yet, maybe they're offline too.

Two grey ticks means the message was successfully delivered to your recipient's device. Their phone has it. They may not have opened the chat though.

Two blue ticks means your recipient opened the chat and the message was displayed on their screen. Their app sent a read receipt back to the server, which forwarded it to you.

Each of these is a distinct state in the database. The message record gets updated as it moves through these stages. If you're offline when someone reads your message, those blue ticks will appear the next time your phone connects and pulls the updated status from the server.

Message delivery flow

Handling Media While Offline

Text messages are tiny, a few bytes at most. But photos, videos, voice notes and documents are a different story. You can't realistically queue up a 50MB video and fire it off the moment you reconnect without the user noticing.

Here's how WhatsApp handles it. When you attach a photo and hit send offline, the media file gets saved locally and tagged as "pending upload". The text metadata (who sent it, which chat, what time) goes into the queue just like a regular message. When connectivity returns, the media gets uploaded to WhatsApp's media servers first. Once the upload completes and WhatsApp gets a URL for that file, the message is then sent with a link pointing to that media.

On the receiving end, your friend's phone gets the message with the media URL but doesn't automatically download the file. That's a separate download that happens over their connection, which is why you sometimes see a "tap to download" prompt rather than media appearing instantly. This keeps the sync process fast and lets users decide whether to download large files on mobile data.

Conflict Resolution and Message Ordering

Here's a tricky scenario. What if two people in a group chat both send messages at almost the exact same time while one of them is on a spotty connection? Whose message comes first?

WhatsApp uses server-side timestamps for final ordering. When your message reaches the server, the server stamps it with an authoritative time. That server timestamp becomes the canonical order. If messages arrive at the server out of order (because one person had a delay), the server figures out the right sequence and delivers them in the correct order to everyone.

On your device, you might briefly see messages in a slightly different order before the sync catches up. This is eventually corrected, which is again that eventual consistency idea in action. The goal is that once everyone syncs, the conversation looks the same for everyone.

Reliability vs Real-Time: The Tradeoff

There's a genuine tension here that's worth understanding. If you prioritize reliability (messages always get through, the app never loses your data), you end up with some latency and complexity. If you prioritize real-time delivery (messages arrive instantly with no local queuing), you lose resilience when the network is unreliable.

WhatsApp has clearly chosen reliability. The local queue, the persistent database, the retry logic, all of this adds complexity but means your message almost never gets lost. The tradeoff is that delivery isn't always instant and the two-tick system exists precisely to tell you where in the pipeline your message currently sits.

Why Offline-First Makes the Experience Feel Smooth

Here's the thing about offline-first design that isn't immediately obvious. It actually makes the app feel faster even when you do have good internet. Because the app reads from local storage first and updates the UI immediately without waiting for server confirmation, everything feels snappy. You're not sitting there waiting for a round trip to a server in some data center. You type, you send, you see it. Done.

The network operation happens quietly in the background. When the server confirms, the status updates. But the user experience is driven by local state, not network state. This is a fundamental design philosophy and it's the reason modern apps like WhatsApp, iMessage, and Telegram feel so much more responsive than older web-based messaging tools that required a live connection for every single action.

Putting It All Together

So next time you tap send in a tunnel, here's what's silently happening on your phone. Your message is written to a local SQLite database. The queue manager picks it up and holds it. The UI reads from the local database and shows you your message immediately. When the connection returns, the queue drains in order to the server, the server delivers it to your recipient, and both devices update their local databases with the new status. The ticks change color. Everything catches up.

It's a beautifully engineered illusion of simplicity sitting on top of a surprisingly sophisticated system. And the next time someone says "I sent you a message, didn't you get it?", you can explain exactly why the answer might be more complicated than it sounds.


Hope you liked this blog. If thereโ€™s any mistake or something I can improve, do tell me. You can find me on LinkedIn and X, I post more stuff there.

Top comments (0)