Course contentsShow
← System Design
Lesson 1702 of 1,91941. Real-World System: Notification SystemFree lesson

User Preferences Lookup

Fast retrieval of user notification preferences from cache or database to filter channels and timing.

User Preferences Lookup

What You'll Learn

You'll learn how to efficiently retrieve user notification preferences to determine which channels and when to send notifications, a critical filter in any scalable notification system.

Why User Preferences Matter

Not every user wants every notification on every channel. Before sending a notification, your system must quickly answer: Does this user want this type of message? On which channels? At what times?

Without fast preference lookups, you'd either spam users (causing opt-outs and complaints) or slow down your entire notification pipeline with database queries.

Core Architecture

User preferences typically include:

  • Channel opt-ins: email enabled, SMS disabled, push enabled
  • Notification types: security alerts only, no marketing
  • Quiet hours: no notifications between 10 PM–8 AM
  • Frequency caps: maximum 5 emails per day

Lookup Flow

Worker receives notification →
  Check cache for user:123 preferences →
    Cache hit? Use cached preferences
    Cache miss? Query database → Store in cache
  → Filter channels and timing
  → Proceed or skip delivery

Cache-First Strategy

Store preferences in Redis or Memcached with user ID as key. When a worker needs preferences:

  1. Cache hit (99% of cases): sub-millisecond lookup
  2. Cache miss: query database, populate cache with TTL (e.g., 1 hour)
  3. Updates: invalidate cache entry when user changes settings

This pattern transforms potentially millions of database queries per second into fast in-memory lookups, preventing your database from becoming a bottleneck in the notification pipeline.

Handling Stale Data

With caching, preferences might be slightly stale (up to TTL duration). For most notifications, eventual consistency is acceptable—users understand a brief delay when changing settings.

Key Takeaway: Fast user preference lookups via cache-first architecture enable real-time filtering of notification channels and timing without database bottlenecks, respecting user choices at scale.