Geo-Targeted Emergency Alerts for Travelers at Scale
System DesignModel answerLast updated
Design a platform that detects natural-disaster zones from external feeds and quickly alerts travelers who are in, or about to arrive in, the affected area without duplicate messages.
Geo-Targeted Emergency Alerts for Travelers
You work on a travel platform with about 50 million active users. Design a system that warns users when a natural disaster (hurricane, earthquake, wildfire, flood) affects the area where they are, or the area they are about to visit.
What the system must do
- Pull disaster events from public agency feeds. Each event arrives as a geographic polygon with a severity, a start time and an expiry, and it may be updated several times.
- Alert users who are currently inside the affected area.
- Alert users who have a booking (stay, flight, or rental) in the affected area within the next 48 hours.
- Let users choose channels (push, email, SMS), set a minimum severity, or opt out entirely.
Non-functional targets
- Alerts reach users within 2 minutes of an event being ingested.
- Support 50M active users worldwide.
- High delivery rate and few false positives (do not alert people who are not actually affected).
- Survive large bursts, such as a single event affecting millions of people.
What to cover in your answer
- A high-level architecture, described in text.
- Data stores, schema, and the geospatial indexing approach (for example H3, S2, or a quadtree), with justification.
- How you map both live locations and future itineraries to disaster zones.
- How you guarantee a user is not notified repeatedly for the same event, even with retries, overlapping feeds, and polygon updates.
State your assumptions and do back-of-the-envelope numbers for write rate and peak send rate.
Hints
Hint 1
Size the problem first: how many location writes per second, and how many messages per second must you send to finish a 2M-user fan-out in about a minute?
Hint 2
Convert each disaster polygon to a set of hierarchical grid cells, and keep reverse indexes from cell to users (live) and from cell plus date to bookings (itinerary). Finish with an exact point-in-polygon test to remove boundary false positives.
Hint 3
Think about users who move into an already-active zone after the event was processed, and about what should and should not change the idempotency key (feed version versus severity level).
Hint 4
Separate the pipeline into stages joined by queues (resolve zone, match users, orchestrate, send per channel) so a burst is absorbed by the queue rather than by the senders.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size
- Live location: assume 20% of 50M users (10M) share location every 10-15 minutes, so roughly 10-15k writes/s, with peaks near 3x.
- Bookings: about 5M reservations begin in any rolling 48-hour window. They change slowly.
- Events: hundreds per day including updates. Low volume, but polygons can have thousands of vertices.
- Worst-case fan-out: a hurricane or major earthquake may affect 1-3M users. If matching takes about 60 s of the 120 s budget, sending 2M messages in the remaining time needs about 35k sends/s across channels.
- Assumptions to confirm: "currently there" and "booking there" are two separate matching paths; escalation in severity triggers a new alert; SMS is reserved for the highest severity because of cost.
2. Interfaces
- Internal event ingest:
{event_id, source, version, severity, polygon (GeoJSON), starts_at, expires_at}. - Location update:
{lat, lng, accuracy, ts}, sent by the client only on significant movement. - Preferences:
{channels, min_severity, opt_out_all}. - Public advisory page by alert id, served from a CDN so links in messages do not hit the backend.
3. Geospatial indexing and storage
I would use H3 at resolution 7 (about 5 km² per cell). Hexagons have uniform neighbor distance, and polyfill and compact turn polygons into cell sets directly. S2 is equally valid. A quadtree is typically held in memory and is harder to shard and update at this scale.
| Data | Key | Store |
|---|---|---|
| Live index | cell -> set(user_id) with ~6h TTL | Redis Cluster |
| Last location | user_id -> cell, lat, lng, ts | Redis or DynamoDB |
| Itinerary index | partition (cell, date) | Cassandra or DynamoDB |
| Events | (event_id, version) with polygon, severity, compacted cells | Postgres with PostGIS |
| Preferences | user_id | DynamoDB plus cache |
| Notification ledger | idempotency_key | DynamoDB, conditional writes, 30-day TTL |
Partitioning bookings by (cell, date) means a "next 48 hours" query touches only two or three date partitions per cell.
4. Architecture
- Ingestion adapters poll or subscribe to agency feeds, normalize them, dedupe on
(source, source_event_id, version), and publish to a Kafkaeventstopic. - Zone resolver polyfills and compacts the polygon, splits the cell list into shards of roughly 500 cells, and emits match tasks.
- Matcher workers (horizontally scaled) read live users from the cell sets and bookings from the itinerary index, then run an exact point-in-polygon check to drop boundary-cell false positives. Output goes to a candidates topic keyed by
user_id. - Orchestrator applies preferences and severity thresholds, merges "live" and "booking" reasons into one message, performs the idempotency claim, localizes the template, and routes to per-channel priority topics.
- Channel senders (push, email, SMS) wrap providers with token-bucket limits, retries with backoff, circuit breakers, and channel fallback. Receipts flow back to the ledger, and poison messages go to a DLQ.
The alert path only reads precomputed indexes. Location and booking services keep those indexes current independently (booking changes via CDC).
5. Live versus itinerary mapping
- Moving users: when a location update crosses a cell boundary, move the user between cell sets. Only a fraction of updates cross a boundary, which cuts write load. TTL removes stale positions.
- Users entering an active zone later: the location service keeps an in-memory set of currently active disaster cells. An update landing in one emits a candidate immediately. Without this, someone driving into the zone after ingestion would never be warned.
- Bookings: indexed by destination cell and date, refreshed by CDC and a daily job. A booking made after the event is checked against active disasters at booking time, which also gives a useful warning in the purchase flow.
6. Idempotency
Duplicates come from queue redelivery, several providers reporting the same event, and polygon refreshes.
- Key:
hash(user_id, canonical_event_id, severity_level). Feed version is deliberately excluded so hourly polygon refreshes do not re-alert. A severity escalation changes the key and legitimately re-notifies. - Canonical event: merge reports from different providers by type, time window, and polygon overlap (IoU above a threshold).
- Atomic claim: a conditional write (
attribute_not_exists) to the ledger before enqueueing a send, with a RedisSETNXin front to absorb hot traffic. - Provider level: pass the key as message id or collapse id so a retry after a timeout collapses on the device.
- State machine:
CLAIMED -> SENT -> DELIVERED/FAILED. Only staleCLAIMEDentries are retried. This yields at-least-once delivery with an effectively-once user experience.
7. Bursts and trade-offs
- Sharding by cell parallelizes matching. Very dense cells (city centers) can be split to a finer resolution.
- Kafka decouples matching from sending, so a spike becomes queue depth rather than dropped work. Autoscale on lag.
- Priority topics ensure that critical alerts are not stuck behind low-severity email.
- Precision versus recall: coarse cells increase candidates, but the exact polygon test restores precision. For life-safety events, lean toward recall and include an "as of" timestamp in the message.
- Privacy: store only the last known location with a TTL, honor opt-out at the orchestrator, and avoid putting exact coordinates in logs.
8. Common mistakes
- Including feed version in the idempotency key, causing repeated alerts.
- Only matching at ingestion time and missing users who arrive later.
- Skipping the exact polygon check and alerting people on the wrong side of a boundary.
- Sending synchronously from the matcher, so provider slowness stalls matching.
- Not sizing for the peak, then discovering provider rate limits make the 2-minute target impossible. Pre-negotiate throughput and spread across multiple providers.
9. Monitoring
Track end-to-end latency (ingest to provider accept), match-stage lag, per-channel success rate, duplicate-suppression count, and opt-out violations (target zero). Run periodic drills with synthetic events against test users.