Lesson 5 of 15
33. Design a Notification System

33.4 What do we store?

3 min read+10 XP
notification_types type, category (security | transactional | marketing), channels allowed, priority, template ids per channel and language templates id, channel, language, version, body with placeholders preferences user_id, (category, channel) → opted in?, quiet hours, time zone, daily marketing cap, language devices user_id, push token, platform, last seen (tokens go stale, Chapter 21) notifications id, idempotency_key (unique), user_id, type, status per channel, provider message id, timestamps (the status store) otp phone, hmac(phone + code), expires_at, attempts (Redis, with TTL)

Interviewer pushback:

  • "Why store OTPs in Redis and not the database?" → They live for 5 minutes, are read once or twice, and need a TTL. Redis with a replica fits; a lost OTP means the user taps "resend".

Memory code: "Accept fast, deliver later; the OTP never leaves the building in plain text."