KatInterview

Distributed Cache and Compute Service Architecture

System DesignModel answer
HardModel answerSystem Designcachingconcurrencyscalability

Last updated

Design a thread-safe in-memory cache with LRU eviction and a CPU-intensive reconciliation service that handles traffic spikes and manages computational limits.

You need to architect two production services for a financial platform:

Service 1: In-Memory Cache with LRU Eviction

Build a caching layer that stores key-value pairs with automatic eviction when capacity limits are reached. The cache must:

  • Support concurrent reads and writes safely across multiple threads
  • Evict least-recently-used entries when memory or entry-count limits are exceeded
  • Handle time-based expiration (TTL) for cached entries
  • Scale horizontally across multiple server instances
  • Provide visibility into cache performance and hot-key patterns

Service 2: Financial Reconciliation API

Design an API that finds combinations of financial transactions summing to a target amount (a variant of the subset-sum problem). The service must:

  • Handle normal traffic of 200 requests/second and spikes up to 2,000 requests/second
  • Process inputs containing up to 10,000 candidate transactions per request
  • Enforce time limits (median 30ms, p99 2s, hard cap 5s) and return partial results when needed
  • Prevent duplicate processing of identical requests
  • Scale horizontally without shared mutable state between workers

For each service, specify:

  1. API design and interfaces
  2. Core data structures and concurrency mechanisms
  3. Scaling strategy and capacity estimates
  4. Failure modes, monitoring, and operational considerations
  5. Key trade-offs in your design choices

Provide concrete numbers and explain how you would validate the design meets requirements.

Hints

Hint 1

For the cache, consider how read operations affect eviction order and what that means for concurrent access patterns

Hint 2

The reconciliation problem is NP-complete in the worst case—your design must prevent unbounded resource consumption

Hint 3

Think about the consistency model: what happens when cache instances diverge or when duplicate reconciliation requests arrive simultaneously?