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

Client-Side Deduplication

Building client logic to detect and discard duplicate notifications using notification IDs.

Client-Side Deduplication

You'll learn how to build client logic that prevents duplicate notifications from appearing to users, even when the server delivers them multiple times.

Why Client-Side Deduplication Matters

Even with server-side safeguards, duplicate notifications can slip through—network retries, multiple device connections, or aggressive retry logic all contribute. The final line of defense is the client application itself, which can intelligently filter duplicates before displaying them to users.

Think of it like mail delivery: even if your mail carrier accidentally brings the same letter twice, you recognize it's a duplicate when you open your mailbox and simply discard the second copy.

How It Works

The client maintains a local cache of recently received notification IDs (typically a hash set or sliding window buffer). When a notification arrives:

  1. Extract the notification ID from the payload
  2. Check the local cache for this ID
  3. If found → silently discard (it's a duplicate)
  4. If new → display to user and add ID to cache
  5. Expire old entries after a time window (e.g., 24 hours)

This cache can live in memory for active sessions or in local storage (like localStorage on web, or app preferences on mobile) to survive app restarts.

Storage Considerations

Keep the cache size bounded—store only IDs from the past 24-48 hours. Use a ring buffer or LRU cache to automatically evict old entries. This prevents memory bloat while covering the typical retry window where duplicates appear.

The client must handle notifications being delivered out of order, so timestamp-based filtering alone isn't enough—ID-based deduplication is essential.

Key Takeaway:
Client-side deduplication using notification IDs provides a final safety net against duplicates, protecting user experience even when upstream systems retry or fail gracefully.