KatInterview

Shared Storage Allowance Service Across Many Products

System DesignModel answer
HardModel answerSystem Designsystem-designdistributed-systemsconsistency

Last updated

Design a globally consistent service that tracks one storage allowance per user across several products, guaranteeing usage never exceeds the limit while staying fast and available.

Several products (for example a file-storage app and a photo app) share a single storage allowance per user, such as 100 GB in total. Design the central service that tracks and enforces this allowance.

Required operations

  1. Consume allowance when a product stores data.
  2. Release allowance when data is deleted.
  3. Optionally, query the user's current allowance and usage.

Non-functional goals

  • A user must never exceed their limit, not even briefly and not under concurrent requests from different products or regions.
  • Strong consistency and high availability.
  • Low latency wherever possible.
  • Scale to millions of daily active users and very high request rates.

Your answer should cover

  • API design (consume, reserve, confirm, release, query) and how idempotency works.
  • Storage choice and data model, and whether you need ACID guarantees.
  • Read and write paths, replication and acknowledgement rules that prevent double-spending.
  • Handling concurrency across services and regions.
  • A state model for allowance (available, reserved with expiry, occupied) plus timeout and recovery behavior.
  • Synchronous vs asynchronous processing, failure handling and retries.
  • Sharding, multi-region disaster recovery and failover.
  • Whether to cache, and how to keep any cache consistent.
  • Backpressure, rate limiting and hot-key mitigation.
  • Monitoring, SLOs and capacity planning.

Hints

Hint 1

Treat 'used + reserved <= limit' as a hard invariant and ask which storage and transaction design can enforce it under concurrency, rather than starting from caching or throughput.

Hint 2

Key every table by user so that each operation touches one shard and one transaction; then think about what a conditional update gives you that read-modify-write in application code does not.

Hint 3

Separate operations that must be synchronous (anything that grows usage) from ones that can be delayed safely (releases), and ask what a delayed or lost message does to the invariant in each case.

Hint 4

Model a reservation with an expiry and decide what happens when a confirm arrives after the expiry; also decide whether the service fails open or closed when it is unreachable.