DEV Community

Royal Simpson Pinto
Royal Simpson Pinto

Posted on Edited on

When There Is No Internet: Delay-Tolerant Networking and Epidemic Routing Explained

Most of the networking we write code against quietly assumes one thing: that a path exists. When your app calls an API, it trusts that there is an unbroken chain of links from your phone to the server, right now, all at once. Routers along the way forward your packet the instant it arrives, and if any hop is missing, the whole thing fails.

But think about a music festival with 40,000 people, a subway car deep underground, a disaster zone where towers are down, or a rural valley with no coverage. There is no continuous path. The classic model just gives up. Delay-tolerant networking (DTN) starts from the opposite assumption: the network is usually broken, and connectivity shows up in brief, unpredictable moments. The job is to move a message anyway.

I ran into this head-on while building Kabootar, an offline mesh messenger that carries messages phone to phone over Bluetooth and Wi-Fi with no servers and no cell towers. Let me walk through the two ideas that make it work.

Store-carry-forward: the mailbox in your pocket

In a normal network, a router does store-and-forward. A packet lands, the router looks up where it goes next, and it forwards it, all in milliseconds. The "store" part is tiny because the next hop is always available.

DTN adds a middle word: store-carry-forward.

  1. Store. A node receives a message and holds onto it in durable storage. Not for milliseconds, but for minutes or hours.
  2. Carry. Here is the twist. The node is a phone, and the phone moves. It physically transports the message through space in someone's pocket.
  3. Forward. When that phone comes near another phone, the two connect over Bluetooth or Wi-Fi and hand the message across.

The mental model that made this click for me: it is the postal service, not the telephone. A letter does not need an open line from sender to recipient. It gets held at one post office, driven to the next, held again, and passed along until it arrives. Each leg happens when it can, and the message survives the gaps in between.

This reframes what a "connection" even is. You no longer need a path that exists all at once. You need a sequence of brief, overlapping contacts that, stitched together over time, eventually reaches the destination. In DTN research this is called a time-varying or contact graph, and the beautiful part is that no single node has to see the whole thing.

Epidemic routing: spread it like a rumor

Once messages hop between phones, the next question is: which phones? In a normal network a routing table tells you the next hop. But in a crowd of moving strangers, nobody has a reliable map, and the map would be stale by the time you read it.

So the simplest robust strategy is to stop trying to be clever about direction and instead spread the message everywhere, the way a rumor or a virus moves through a population. This is epidemic routing.

The rule is almost embarrassingly simple. Whenever two nodes come into contact, they compare which messages each one is holding and exchange the ones the other is missing. That is it. Every encounter is a chance to infect a new carrier. A message you sent starts on one phone, becomes two, then four, then rippling outward through everyone the carriers happen to meet.

Why lean on something this blunt? Because it is maximally resilient. Epidemic routing needs no knowledge of topology, no addresses of intermediate nodes, no coordination. If any sequence of contacts can possibly deliver the message, flooding will find it, and it will find it along the fastest available path because it tries all of them at once. When the network is chaotic and unpredictable, brute-force redundancy beats fragile intelligence.

To make the exchange efficient, nodes do not blindly re-send everything. In Kabootar, each message carries a unique ID, and when two devices meet they first trade a compact summary of the IDs they already hold, then transfer only the genuinely new ones. Same epidemic idea, far less wasted radio time.

The problem epidemic routing creates, and the fix

If you have been reading closely, you have already spotted the flaw. If every phone keeps handing a message to every other phone forever, that message never dies. It keeps replicating across the whole population long after it has been delivered, burning battery and radio bandwidth on copies nobody needs. Left alone, epidemic routing floods the network into the ground.

The fix is end-to-end delivery acknowledgments.

When a message finally reaches its intended recipient, the recipient generates a tiny acknowledgment: "I have message X, you can stop carrying it." And here is the elegant part. That ack spreads through the exact same epidemic mechanism. It rides phone to phone like an antibody. When a carrier receives the ack for a message it is still holding, it deletes its copy and, from then on, refuses to accept or spread that message again.

So the system has two epidemics running in tension. The message floods outward looking for its recipient. Once found, the acknowledgment floods outward behind it, cleaning up the copies. Delivery triggers its own cleanup. That is what keeps a serverless mesh from drowning in its own redundancy, and it is the piece people most often forget when they first reach for flooding.

The honest caveat: you pay for resilience

I do not want to oversell this. DTN and epidemic routing buy reliability in a disconnected world, but the price is real, and it is two-fold.

Latency. There are no guarantees about when a message arrives, only that it eventually will if a contact path exists. Delivery depends on people physically moving and bumping into each other. In a dense crowd that might be seconds. In a sparse rural setting it could be hours, or never. This is not a chat app that replaces WhatsApp for a quick "on my way." It is a fundamentally best-effort, eventually-delivered system, and you have to design the user experience around uncertainty rather than hide it.

Overhead. Flooding means many redundant copies of every message riding around on many devices, each transfer costing battery and radio time. Acknowledgments claw a lot of that back, and summary exchanges trim the rest, but you are still spending far more total energy than a single direct path would. Resilience is not free; you are trading efficiency for the ability to work at all when nothing else does.

For the environments DTN targets, that trade is worth it. When the alternative is no communication whatsoever, a message that arrives late and cost some battery is a spectacular deal.

Wrapping up

Strip away the jargon and DTN is two humble ideas. Hold a message and physically carry it until you meet someone closer to the destination. Spread it like a rumor so that if any path exists, it gets found, then let delivery acknowledgments spread the same way to clean up after themselves. No servers, no towers, no assumption that the network is even there.

That is the entire foundation Kabootar runs on, and honestly the ideas are far more approachable than the reputation of "distributed systems" suggests. If you want to see store-carry-forward and epidemic routing as actual working code over Bluetooth and Wi-Fi, the project is open source at github.com/royalpinto007/Kabootar. Poke around, and maybe let a message travel a few pockets before it reaches you.

Top comments (0)