← Building blocks

Reach devices through platform push

Real-time & streamingfundamental

The app is closed; you cannot hold a socket.

Say it like this

When the app is closed I cannot hold a socket, so I send a small notification through APNs or FCM using the stored device token, and the app fetches the real content when it opens.

Basic solution

Send through the platform push service using the device token; keep payloads small and fetch details on open.

APNsFCMWeb Push

Token registry, provider send, fetch on open

Devices register tokens; senders build a small payload per token and call the provider; the app fetches real content on open. Provider feedback prunes dead tokens and throttles the sender.

How it works

  1. On install or login, the app asks the operating system for a push token, an opaque string that identifies this app on this device to Apple's or Google's push service. The app sends it to the backend, which stores (user_id, device_id, platform, token, updated_at).
  2. When a notification is due, the sender looks up the user's active tokens and builds one small payload per platform: a title and body, a collapse key, a priority flag, and a data map holding a pointer such as a conversation id, never the full content.
  3. The sender calls the provider over HTTP/2 (APNs with a signed JWT, FCM with a service-account credential) and gets a per-token response: accepted, invalid token, rate limited, or a temporary error.
  4. The provider delivers to the device when it has a connection to it. The operating system then either shows the notification on screen or, for a silent push, wakes the app in the background for a few seconds.
  5. When the user opens the app, it reconnects to your servers and fetches the real content from the API using the pointer in the payload. The notification was only a hint that something is waiting.
  6. The provider's responses drive housekeeping: a token reported as unregistered is deleted immediately, a temporary failure is retried with backoff, and a 429 tells the sender to slow down.

Why not put the content in the push

  • Payloads are capped at a few kilobytes, delivery is not guaranteed, and content inside a push bypasses the access checks and end-to-end encryption that the API enforces. The authoritative data lives behind the API.

Worked example

Push for the notification system

  • 50M users with 2 devices each, so 100M tokens at about 200 bytes with metadata: 20 GB of token storage, indexed by user id.
  • 150M push notifications per day on average, about 1,700 per second; a marketing campaign to 20M users in 10 minutes is 33K per second.
  • APNs and FCM both accept tens of thousands of requests per second per connection pool; 16 HTTP/2 connections per sender with 100 streams each give 1,600 in-flight requests. At 50 ms per round trip that is 32K per second from one sender instance; run 4 for the campaign peak.
  • Token churn: about 2 percent of tokens go invalid per month from reinstalls and device changes; the provider reports unregistered on the next send, so 2M tokens are pruned monthly by feedback alone.
  • Delivery: roughly 90 percent of pushes reach a device within a minute; the rest wait for the device to come online. Measuring delivery means tracking the app-open event, not the provider accept.
  • Cost comparison with SMS from the same system: push is effectively free, SMS at 0.01 per message for the same 150M a day would be 1.5M a day.

Variants and when each wins

Alert push with content

  • A title and body that the operating system shows on the lock screen. It wins for human-readable events people should see at a glance; keep sensitive details out, because it is visible before unlocking.

Silent (background) push

  • No user-visible text; the push only wakes the app so it can sync. It wins as a trigger for a fetch after the inbox write, but the OS rate limits it and may drop it on low battery, so it must never be the only delivery path.

Collapsible push

  • A push carrying a collapse key, which tells the provider to replace any undelivered push with the same key. It wins for conversations: a user who was offline sees one "5 new messages" rather than five separate alerts.

Web Push

  • Push to a browser through a service worker, authenticated with VAPID keys. It wins when the client is a web app; the model is the same, with a different provider per browser vendor.

Recommendation: alert pushes with minimal content, collapse keys per conversation, silent pushes to prompt a sync, and the API as the only source of content.

Failure modes

Sending to dead tokens

  • The delivery rate drops month after month and eventually the provider throttles you. It happens because tokens that were invalidated by reinstalls and device changes are never removed, so a growing share of sends go nowhere. Delete a token the moment the provider reports it as unregistered, and have the app re-register its current token on every launch so the newest one always wins.

Duplicate notifications across devices

  • A user with a phone and a tablet gets the same alert on both and reads it on one. It happens because the sender pushes once per token with no shared state between devices. Keep sending to all devices but include the message id, and when the user reads on one device, send a silent push to the others so they clear the alert.

Provider outage

  • Every send times out for an hour. It happens because APNs or FCM is having an incident, and there is nothing you can do about that. Put a circuit breaker in front of each provider so senders fail fast, queue the pushes instead of dropping them, and rely on the client syncing when it next opens; because content lives in the API, nothing user-visible is lost.

Rate limiting during a campaign

  • The provider returns 429s and a backlog builds. It happens because a marketing campaign sends faster than the provider's per-app limit allows. Put a token bucket sized to the limit in front of each provider, and give campaigns their own low-priority queue so transactional pushes never wait behind them.

Content leak on the lock screen

  • Message bodies are readable without unlocking the phone. It happens because the full message text was placed in the alert body. Use generic alert text for sensitive apps and fetch the body on open; for end-to-end encrypted chat this is not optional, because the server does not have the body anyway.

Interviewer follow-ups

Answer out loud before you open each one.

Why is a push not a reliable delivery channel?

Providers deliver at most once and may drop, delay or collapse pushes, especially silent ones on low battery; a device that is off for a day receives only the last collapsed one. So the push is a hint to open the app, and the durable inbox or API is what guarantees the content arrives.

How do you keep the token table clean?

Two mechanisms: the app re-registers its current token on every launch so the row is refreshed, and the sender deletes any token the provider reports as unregistered or invalid. Together they bound stale tokens to roughly one send cycle.

What is a collapse key and when do you use it?

A string on the push that tells the provider to replace any undelivered push with the same key. Use it per conversation or per entity so an offline user gets one summary rather than a pile, and never use it for distinct transactional events like two separate orders.

How do you measure whether pushes are working?

Track three funnels: accepted by the provider, delivered to the device (where the platform reports it), and opened by the user, each by platform and app version. Accept rate catches token problems, delivered catches provider or OS issues, opened catches payload or relevance problems.

Connections

In study paths
Real-time delivery
Pairs with
Deliver to users who are offline · Decouple producer from consumer · Keep urgent work ahead of bulk work · Retry transient failures carefully · Stop calling a failing dependency
Pulls against
Keep the server out of the content
Used in
Notification System · Chat App (WhatsApp / Messenger)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon DynamoDBDevice tokensFirestore, BigtableCosmos DBScyllaDB, Apache Cassandra
Amazon EC2 Auto ScalingPush sender, Content APICompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon SQSpush queuePub/Sub, Cloud TasksService Bus queues, Queue StorageRabbitMQ, ActiveMQ