Skip to the page

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.

The 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

  1. Design a notification service.
  2. How do you keep OTPs fast during a marketing blast?
  3. Design a distributed job scheduler.
  4. How do two schedulers avoid running the same job?
  5. What if a worker dies in the middle of a job?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview