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.
- Save it first. A new message goes into a safe list for you in Redis. It stays there until your phone confirms it.
- Find your pod. Pulse looks up which pod your phone is connected to.
- Deliver it. The message goes into that pod’s queue, and the pod sends it to your phone.
- 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.
- Catch up. If your phone was offline, it reconnects, and Pulse sends everything it missed.
new message ─► save in safe list ─► find the user's pod ─► that pod's queue ─► phone phone says "got it" ─► remove from safe list phone reconnects ─► send everything still in the safe list
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.