Katkat

Design a device owner lookup service

SnapchatSoftware Engineer · Onsite

Last updated

This question tests the ability to design a distributed system for tracking the mapping between ephemeral devices and their currently signed-in users, focusing on handling event concurrency and high-throughput read/write operations.

Problem Statement

Design a Device Owner Lookup Service for a platform like Snapchat. The system must support two primary operations:

  1. UpdateOwnership(device_id, user_id, timestamp): Triggered whenever a user signs into a device. Events might arrive out-of-order due to network latency.
  2. GetOwner(device_id): Returns the current user associated with a given device_id.

Functional Requirements

  • The service should reliably return the owner associated with the most recent login event (based on timestamp).
  • The service needs to handle millions of concurrent users and global scale.
  • Read latency should be sub-50ms at the 99th percentile.

Non-Functional Requirements

  • High availability and consistency.
  • Resiliency against out-of-order events (e.g., an event with an older timestamp arriving after a newer one).
  • Scalability: The system should handle high write volumes during peak hours.

Expected Deliverables

  • Define the API interface.
  • Propose a data schema for storage.
  • Describe the architecture, including how you handle event ordering and eventual consistency.
  • Discuss trade-offs between read and write performance.

Hints

Hint 1

Consider using a distributed key-value store with strong consistency features or a database that supports conditional updates (e.g., compare-and-swap).

Hint 2

Think about how to handle out-of-order events by using the event timestamp to ensure only newer updates override existing records.

Hint 3

Discuss whether a caching layer is necessary to meet the read latency requirements and how to keep it synchronized with the primary database.

Follow-up questions

  • How would you handle a scenario where a device is shared by multiple users who sign in and out frequently?
  • If the write traffic for a single device ID becomes a hot spot, how would you re-architect the storage to handle the load?
  • How would you modify the system to provide an audit log of all historical owners for a device?