How it works
Separate the durable message log from ephemeral connection state and delivery jobs. Replicate or otherwise protect the log, monitor write latency and lag, and keep a retryable queue for fanout. A worker crash should leave a job available for another worker. That is at-least-once processing, where work may repeat but is not dropped, so effects must be idempotent: running them twice gives the same result as running them once.
Follow one crash. A worker takes the job for message 1042 from a queue with a 30-second lease, which Amazon SQS calls a visibility timeout. It pushes to Ben’s phone, then dies before acknowledging. After 30 seconds the job reappears, and a second worker pushes to the phone and laptop. The phone sees a known message ID and drops the repeat; the laptop gets its first copy. Writing the job in the same database transaction as the message, a pattern called a transactional outbox, means a crash cannot leave a message with no job.
Watch socket count per gateway, reconnect rate, outbound queue depth, end-to-end delivery delay, replay backlog, failed pushes, and storage errors. Add capacity based on concurrent connections and message fanout rather than daily users alone. Rate limits and backpressure, slowing output a client cannot absorb, protect gateways from slow clients or abusive senders.
A full end-to-end encryption requirement would change key management, multi-device handling, moderation, and server-side search. Media attachments would add object storage, upload processing, scanning, and CDN delivery. Keep those as explicit next design changes rather than quietly assuming this text-only system already supports them.
A delivery worker crashes after pushing to one device but before acknowledging its job. What happens when the job runs again?
The job is retried. The device may receive the event again, so it deduplicates by stable message ID. The canonical record remains one message, while at-least-once delivery and idempotent processing make recovery safe.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Durable storage, retryable jobs, idempotency, and replay each address a different failure.
- Measure connections, fanout, lag, and recovery; revisit the design when scope changes.