SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • Long Polling
  • Server-Sent Events (SSE)
  • WebSockets
  • Webhooks
  • WebRTC
  • Short Polling
  • Push Notifications
  • MQTT
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/Real-Time Communication

Push Notifications

Reach a phone even when the app is closed, through the phone maker's push service.

⏱ 13 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A push notification is a short message that appears on a phone or in a browser, even when your app is closed. Your server does not talk to the phone directly. It hands the message to the platform's push service, which delivers it.

  • Each app install gets a device token (a registration id). Your server stores it and uses it as the address.
  • Delivery is best effort. A message can be delayed, merged or dropped, so never rely on it alone.
  • The message is small. Send an id or a short text, and let the app fetch the details.
  • The user must allow notifications, and can turn them off at any time.

02Concept: What is it?

An app that is not running cannot keep its own connection open for hours. That would drain the battery. Instead, the phone keeps one shared connection to its maker's push service: Apple's APNs for iPhones, Google's FCM for Android, and browser push services for web push. Your server talks to that service, and the service reaches the phone.

The journey of one push

From your server to the screen
πŸ–₯️Your serverhas the device token
→↓send(token, message)
πŸ›°οΈPush serviceAPNs, FCM, web push
→↓shared connection
πŸ“±Phone or browsershows the alert
You Platform User
Your server never connects to the phone itself. The push service is the middle-man.

Getting a token

When the user installs the app and agrees to notifications, the app asks the operating system for a device token. The app sends that token to your server and you save it next to the user id. A user with a phone, a tablet and a browser has three tokens. Tokens can change, so the app must send the new one when it does.

🧠A push is a nudge, not a guarantee
Treat a push as a hint that something happened. The real data should live on your server, and the app should be able to fetch it when it opens.

03Real-Life Example

🍡The doorbell with a delivery service
You want to tell a friend that dinner is ready, but you cannot phone them directly. You give a note to a courier company that already knows where your friend lives. The courier carries many notes at once and delivers them when they can. If your friend is out, the courier holds the note for a while and tries again. If the note says β€œvalid for 30 minutes” and your friend gets home after an hour, the courier throws it away. If your friend has moved out of the city, the courier tells you β€œno such address”.
Courier delivering a note
Push notification
The courier company
APNs, FCM or a browser push service
Your friend's address on file
The device token
The note
The push payload (small)
'Valid for 30 minutes'
Time-to-live (TTL)
Holding it until your friend is home
Store and forward for offline devices
'No such address'
Token not registered, so you delete it
Your friend can refuse notes
The user turns notifications off
Three things that can happen
πŸ“±Device onlinedelivered at once
πŸ“΄Device offlineheld, then delivered or expired
πŸ—‘οΈApp uninstalledtoken rejected

04Why Do We Need It?

πŸ””Reach closed apps
A message can arrive when the app is not running and the phone is locked.
πŸ”‹Battery friendly
One shared connection for all apps is far cheaper than every app polling.
↩️Bring users back
A good notification is a reason to open the app again.
⚑Timely news
Time-sensitive things (a delivery, a message, a security alert) reach the user fast.
πŸ”„Wake the app to sync
A silent push can tell the app to fetch new data in the background.
πŸ“No servers to hold connections
The platform holds the long-lived connections, not you.
Push lets a server reach a device it cannot connect to, using the platform's own always-on channel.

05Where Do We Use It?

πŸ’¬Chat apps
β€œNew message from Sam” when the chat app is closed.
🚚Delivery and rides
Your driver is arriving. Your parcel is out for delivery.
πŸ”Security alerts
A login from a new device, or a request to approve a sign-in.
πŸ“°News and sport
Breaking stories and match results.
πŸ›’Shopping
A price drop, an item back in stock, an abandoned cart.
πŸ”„Background sync
A silent push asks the app to refresh its data.

06Types / Parts / How It Works

The platforms

PlatformPush serviceAddress you storeNotes
iPhone and iPadApple Push Notification service (APNs)Device tokenYour server authenticates to Apple, using a key or a certificate
AndroidFirebase Cloud Messaging (FCM)Registration tokenAlso used to reach other platforms through one API
Browsers (web push)The browser's own push serviceA subscription (an endpoint and keys)Needs a service worker and the user's permission

Kinds of message

KindWhat the user seesTypical useCaution
Visible (notification)An alert on the screenMessages, offers, alertsUsers can mute or block them
Silent (data)Nothing. The app wakes and runs brieflyTell the app to syncThe system may limit or delay these
Topic messageAn alert sent to everyone who subscribedNews, sport, a regionGood for broadcast, not for private data

What a send looks like

General idea (each provider has its own exact format)
POST to the push service
  to:      <device token>
  ttl:     1800            <- seconds the service may hold it
  priority: normal | high
  collapse_key: "chat-42"  <- a newer message replaces an older one
  payload: {
    title: "Sam",
    body:  "Dinner is ready",
    data:  { messageId: "m-981" }   <- an id, not the secret content
  }

Scaling out to millions

  1. 1
    An event happens
    For example, a breaking story, or a message for one user.
  2. 2
    Find the tokens
    Look up the user's tokens, or the subscribers of a topic.
  3. 3
    Put jobs on a queue
    One job per batch of tokens, not one request per user in a web call.
  4. 4
    Workers send in parallel
    Each worker calls the push service. Retry on temporary errors, with backoff.
  5. 5
    Read the answers
    Delete tokens the service says are no longer valid. Record results.
VisualizerPush pipeline: device state, TTL and fan-outStep through one push. Switch the device to offline or uninstalled, move the TTL slider, and see how long a send to millions would take.
Where is the user's device?
Kind of message
πŸ–₯️Your serverfinds tokens
→↓
πŸ”‘Device tokenone per app install
Step 1 of 5
1. Your server decides who to notify
Something happened (a new message, a delivery update). Your server finds the device tokens for the user and builds a small visible message.
Result
delivered
Time to send to everyone
1.7 min
10,000 pushes / s
Delivered within moments. The user sees the notification.

A simplified, deterministic model. Delays, the 500 pushes per second per worker and the TTL values are illustrative. Real push services are best-effort: they may delay, merge or drop messages, and each platform has its own limits and rules.

07How to Use It / Steps / Implementation

Doing push well

  1. Ask for permission at a good moment. Explain the value first. A blunt prompt on the first launch is often refused.
  2. Store tokens per device and update them when the app reports a new one.
  3. Clean up. When the push service says a token is invalid or unregistered, delete it. Otherwise you keep sending to nobody.
  4. Keep the payload tiny. Send a title and an id. Let the app fetch the full content from your API.
  5. Never put secrets in a push. The text may show on a locked screen and travels through a third party.
  6. Set a sensible TTL. A β€œyour ride is here” push is useless after ten minutes. Let it expire.
  7. Use a collapse key so that five old β€œnew message” pushes do not pile up behind each other.
  8. Send through a queue with retries, backoff and rate limits, so a big campaign does not overload your servers.
  9. Make it idempotent. A retried send should not show the same alert twice. Use a stable message id.
  10. Always have another way. Keep an in-app inbox or email for anything important.
⚠️Respect the user
Too many notifications make people mute your app or delete it. Let users choose which kinds they get, and cap how often you send.

08Key Terms to Know

TermMeaning in easy words
Push notificationA message delivered to a device by a platform push service
Device tokenThe address of one app install on one device, issued by the platform
APNsApple's push service for iOS and macOS
FCMGoogle's push service for Android, and a common API for other platforms
Web pushPush for browsers, using a service worker and a subscription
PayloadThe small message you send (title, body, and a little data)
TTL (time-to-live)How long the push service may hold a message for an offline device
Silent pushA data-only push that wakes the app but shows nothing
TopicA named group, so one send reaches every subscriber
Collapse keyA label so a newer message replaces an older waiting one
Fan-outTurning one event into many sends, one per recipient

09Pros, Cons and Trade-offs

βœ… Pros
  • Reaches users when the app is closed
  • Battery friendly through one shared connection
  • No connection management on your side
  • Works for both one user and millions (topics)
  • Strong tool for timely alerts
⚠️ Cons
  • Best effort: it may be late, merged or dropped
  • Small payloads and platform limits
  • Depends on third-party services and their rules
  • Users can switch it off at any time
  • Tokens go stale and must be cleaned up

Trade-offs

ChoiceWe gainWe lose
Long TTLMore offline users still get itA stale message may arrive late and look odd
Short TTLOnly fresh messages are shownOffline users miss it for good
High priorityFast delivery for urgent thingsMore battery use. The platform may limit abuse
Data in the payloadThe app can show it without a network callSize limits and privacy risk
Id in the payload, fetch laterSmall and saferAn extra request when the app opens
TopicsOne call reaches many peopleNo per-user personalisation

10Common Problems and Mistakes

Common mistakes

  1. Relying on push alone. It is not guaranteed. A payment confirmation that only goes by push will sometimes be missed.
  2. Never deleting dead tokens. The list grows, the cost grows, and your delivery stats look bad.
  3. Sensitive data in the message. It can appear on a lock screen, and passes through a third party.
  4. Sending one by one in a web request. A big send blocks the request and times out. Use a queue.
  5. Ignoring the platform's limits. Sending too fast, or with too large a payload, gets you throttled or rejected.
  6. Spamming users. Too many pushes lead to muted or deleted apps.
  7. Duplicates on retry. Without a stable message id, a retry can show the same alert twice.

Things to watch

πŸ“‰Delivery rate
Track sent, delivered and opened. A sudden drop often means a certificate or key problem.
πŸ”‘Expired credentials
The key or certificate you use to talk to the platform can expire. Alert before it does.
🧹Token churn
People reinstall and switch phones. Expect a steady stream of dead tokens.
πŸ”•Opt-out rate
If many users switch pushes off after a campaign, you sent too many.

11Real-World Examples

πŸ’¬Messaging apps
Show a message alert, then the app downloads the actual text when opened.
πŸš—Ride and delivery apps
Short-lived alerts such as β€œyour driver has arrived” use a short TTL.
🏦Banks
Approve-this-sign-in pushes, with details kept out of the visible text.
πŸ“°News apps
Topic-based sends reach millions of subscribers with one call.
🧩Push providers
Many companies use a service that wraps APNs, FCM and web push behind one API.
πŸ“Note
Message size limits, priorities and rules differ by platform and change over time. Check the current documentation for APNs, FCM and web push before you build.

12Related Topics to Read Next

Webhooks→

Server-to-server callbacks, a cousin of server-to-device push.

Message Queues→

Used to fan out a big send to many workers.

WebSockets→

A live connection while the app is open.

Retries with Backoff→

How to retry a failed send without making things worse.

Idempotency→

A retried push should not show up twice.

Rate Limiting→

The platforms and your own system both limit sending rates.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”What: a small message delivered by the platform push service (APNs, FCM, web push).
  • βœ”Address: the device token, one per install. Store it, refresh it, delete it when invalid.
  • βœ”Not guaranteed: best effort. It may be late or dropped. Keep another path for important news.
  • βœ”TTL: how long it may wait for an offline device.
  • βœ”Payload: tiny. An id and a short text, never secrets.
  • βœ”Scale: queue, parallel workers, backoff, rate limits, topics for broadcasts.
  • βœ”Be kind: ask permission well, let users choose, do not spam.
  • βœ”One line: β€œHand a short note to the platform courier and let it find the phone.”
← Previous
Short Polling
Next β†’
MQTT