System design prompts · senior
Notification service and job scheduler
Both are queue-based systems: accept work, store it, run it later with retries. The key ideas are priority separation, claiming work safely, at-least-once delivery and idempotent handlers.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Notification API: POST /notifications with userId, templateId, params, channels, priority and idempotencyKey. The service owns templates, preferences, device tokens and contact details.
- Flow: validate, store a row, put it on a queue per channel and priority; channel workers render and call providers (FCM and APNs for push, SMS gateways, an email provider). Status comes back from callbacks and webhooks.
- Separate queues or topics by priority so OTPs and payment messages never wait behind marketing. Retries with backoff and a dead-letter queue. Two or more SMS providers with failover by health. An idempotency key stops a retried job sending twice.
- Check preferences and caps before sending; quiet hours in the user time zone; unsubscribe for marketing. In India SMS needs DLT-registered sender headers and templates, links inside SMS must be whitelisted (since October 2024) and promotional messages respect DND.
- Job scheduler: job definitions with next_run_at in a database indexed by time. Schedulers (one leader, or several each owning a shard) poll a small window of due jobs, claim each with a conditional update or lease (status = queued, lease_until) and push to a queue that workers pull from.
- Exactly-once end to end is not possible. Use at-least-once delivery plus idempotent handlers keyed by a run id. Workers heartbeat their lease; an expired lease puts the run back on the queue.
- Midnight spikes: jitter, priorities, per-team quotas, workers that scale on queue depth. Retries with backoff and a maximum, a dead-letter queue, alerts to the owning team and a run history table.
- Build or buy: cloud schedulers or a durable workflow engine such as Temporal may be enough. Never use cron on one machine.
The red pen
Common traps: mistake → fix
Mistake: One queue for everything is simple
Fix: marketing blocks OTPs.
Mistake: Call the SMS provider inside the order API
Fix: it blocks and fails with the provider.
Mistake: Promise exactly-once
Fix: promise at-least-once with idempotency.
Mistake: SELECT due jobs on a huge table with no index or claim step
Fix: slow and double runs.
Easy to hard
Questions interviewers ask, easy to hard
- Design a notification service.
- How do you keep OTPs fast during a marketing blast?
- Design a distributed job scheduler.
- How do two schedulers avoid running the same job?
- What if a worker dies in the middle of a job?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.