harshil

pulse

Makes sure every live message reaches the right phone, even after the connection drops.

prototypeNode.js2026-03sologithub ↗

what
The delivery part of a chat or call app. When someone sends you an event, Pulse finds the server your phone is connected to and delivers it there.
the hard part
Phones drop their connection all the time. A message must never get lost, and must arrive when the phone comes back.
where it is
A working prototype you can read in one sitting - about 150 lines of core logic.

How it works

A big app runs many copies of its server. Each copy is called a pod — One running copy of the server. A user's live connection is held by exactly one pod at a time.. Your phone keeps one live connection to one pod.

  1. Save it first. A new message goes into a safe list for you in Redis. It stays there until your phone confirms it.
  2. Find your pod. Pulse looks up which pod your phone is connected to.
  3. Deliver it. The message goes into that pod’s queue, and the pod sends it to your phone.
  4. Confirm it. Your phone replies “got it” (an ACK — A short reply that says "I received it". Until the sender gets it, the sender keeps the message and can send it again.). Only then is the message removed from the safe list.
  5. Catch up. If your phone was offline, it reconnects, and Pulse sends everything it missed.

What went wrong

The first version removed confirmed messages by time: “delete everything up to this millisecond”. Two messages sent in the same millisecond have the same time. So confirming one could delete the other before it arrived. Now each confirmation removes exactly one message. Fixed in commit 170be09.

Limits, said plainly

  • A message can arrive twice (if a “got it” is lost, the message is sent again). The phone must ignore a message id it has already seen. This is called at-least-once delivery — Every message arrives one or more times. None is lost, but a message can arrive twice, so the receiver must handle duplicates. delivery.
  • If Redis itself goes down, messages in flight are lost. A real deployment needs a Redis cluster.

The first version of this idea, realtimer, served many customers at once, with API keys and usage tracking.

numbers

valuewhatsource
4Redis keys per user, each with one jobREADME
5functions in the core, about 150 linessrc/eventService.js

explore the code

Explorer 5 parts · tap one
src/eventService.js

All the delivery logic, in five functions - send, read, confirm, resend, and connect. source ↗

src/redis.js

Two connections to Redis. One waits for new messages, so the other is never stuck behind it. source ↗

src/socketHandlers.js

What happens when a phone connects - remember which server it is on, and resend anything it missed. source ↗

src/config.js

The names of all the Redis keys, in one place. source ↗

public/dashboard.js

The live dashboard. Shows each message moving through the system and how long each step took. source ↗

read the code

keys

This page reads like any web page. If you use vim, it also works like vim.

move
j / knext / previous line
gg / Gtop / bottom
Ctrl-d / Ctrl-uhalf a page down / up
]] / [[next / previous heading
H / Lprevious / next project or post
act
Enter or gfopen the link on the current line
Kexplain the term on the current line
/ then n / Nsearch this page
:command line: a page name, help, q
Spacemenu: f find, p projects, w writing
Space a / Ctrl-e / Alt-1…4pin a page, list pins, jump to a pin
Ctrl-oback
Escclose, clear search