Scenario
Your server receives a stream of events from clients. Each event contains:
-
user_id
-
device_id
-
timestamp
(event time)
A device may be associated with different users over time (e.g., shared device, logout/login, resale).
Core requirement
Build a backend service that supports:
-
get_device_owner(device_id) -> user_id
Returns the
current owner
of the device.
Assume “current owner” means the user_id from the latest event by timestamp for that device_id.
Constraints / concerns to address
-
Events may arrive
out of order
.
-
Clients may retry →
duplicate events
.
-
Large scale (many devices; high write QPS; low-latency reads).
-
Define behavior for ties (same timestamp) and missing devices.
Deliverables
-
API design (ingestion + query)
-
Data model
-
Storage and indexing
-
How you handle out-of-order/duplicate events
-
Consistency guarantees and trade-offs
-
Monitoring and operational considerations