← Coinbase Interview InsightsSoftware Engineer

Coinbase·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Coinbase system design round focused on extending a key-value store with TTL support. The question had a lot of moving parts and the discussion went pretty deep into expiration strategies and memory trade-offs.

Questions Asked (4)

Q1

You have an in-memory key-value store with store, read, and scan operations. Extend it to support per-key TTL: store(key, value, ttl) should set an expiry, and reads and scans should not return expired keys. Walk through your design.

System DesignTechnical Trade-offs
Author's notes

I started with lazy expiration because it felt simpler to reason about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a design that stores expiry timestamps alongside values and uses lazy deletion with periodic cleanup. Discuss trade-offs between active and passive expiration, and how to handle scans efficiently without blocking.

Pro tip: Mention that you would use a min-heap or time-ordered data structure to efficiently find expired keys, but avoid over-engineering by noting that lazy deletion is often sufficient for in-memory stores. Also, consider thread-safety and how TTL interacts with concurrent operations.

1. Clarify Requirements

Ask about expected scale, read/write patterns, memory constraints, and whether TTL precision is critical. Confirm if expired keys should be removed immediately or lazily.

2. Data Structure Design

Propose storing each key's value with an expiry timestamp (e.g., in a struct). Optionally maintain a separate min-heap or sorted set of keys by expiry for efficient cleanup.

3. Expiration Strategy

Explain lazy expiration: on read/scan, check if key is expired and skip/delete. Also propose a background thread for active expiration to free memory, discussing trade-offs.

4. Handling Scans

Ensure scans filter out expired keys. Discuss whether to iterate over all keys or use the expiry index to skip expired ones, and how to avoid blocking during cleanup.

5. Concurrency and Trade-offs

Address thread-safety with locks or concurrent data structures. Discuss trade-offs: memory overhead of timestamps, CPU cost of active expiration, and latency impact.

Key Points to Mention

  • Lazy vs. active expiration: lazy on access, active via background thread or min-heap.
  • Storing expiry as absolute timestamp (e.g., Unix time) to avoid drift.
  • Using a min-heap or time-ordered index for efficient active expiration.
  • Thread-safety: locking strategies (e.g., per-key locks, read-write locks) or lock-free approaches.
  • Scan implementation: filtering expired keys and potential performance impact.
  • Trade-offs: memory overhead, CPU usage, and complexity vs. simplicity.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

What are the trade-offs between lazy expiration on access versus running an active background thread that periodically purges expired keys?

System DesignTechnical Trade-offs
Author's notes

This is where I felt more comfortable.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining both strategies clearly, then compare them across dimensions like latency, memory usage, CPU overhead, and consistency. Conclude with a recommendation based on workload characteristics, such as read-heavy vs write-heavy patterns, and mention hybrid approaches.

Pro tip: Emphasize that the choice depends on the specific use case and constraints; showing awareness of hybrid strategies (e.g., lazy expiration with periodic sampling) demonstrates deeper understanding and practical experience.

1. Define the strategies

Briefly explain lazy expiration on access (checking and deleting expired keys when accessed) and active background purging (a thread that periodically scans and removes expired keys).

2. Compare on key dimensions

Analyze trade-offs in terms of latency (access-time overhead vs background CPU usage), memory efficiency (stale keys lingering vs timely cleanup), and system complexity (simplicity of lazy vs thread management and synchronization).

3. Consider workload and scale

Discuss how the choice depends on access patterns (e.g., read-heavy vs write-heavy), key expiration rates, and system scale (single node vs distributed).

4. Mention hybrid approaches

Highlight that many systems combine both: lazy expiration as a fallback and active purging with sampling or adaptive rates to balance overhead and memory.

5. Conclude with a recommendation

Summarize which strategy is preferable under which conditions, and note that the best choice often depends on specific requirements and constraints.

Key Points to Mention

  • Latency impact: lazy expiration adds overhead to every access, while active purging runs in the background but may cause CPU spikes.
  • Memory usage: lazy expiration can lead to memory bloat if expired keys are rarely accessed; active purging frees memory promptly.
  • CPU overhead: active purging consumes CPU cycles continuously, which may be wasteful if expiration rate is low.
  • Consistency and correctness: both ensure expired keys are not returned, but lazy expiration may return stale data if not checked properly.
  • Scalability: active purging may not scale well in distributed systems due to coordination; lazy expiration is simpler but can cause hotspots.
  • Hybrid strategies: e.g., Redis uses lazy expiration plus periodic active expiration with sampling to limit overhead.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

During a scan over a range of keys, should expired keys be silently skipped in the results, or should the scan also evict them as a side effect?

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

Tricky.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints of the scan operation, such as performance, consistency, and side-effect expectations. Then, discuss the trade-offs between silently skipping expired keys versus evicting them during the scan, and propose a solution that aligns with the system's design goals. Conclude with a recommendation and potential implementation considerations.

Pro tip: Emphasize that side effects in read operations can violate the principle of least surprise and complicate error handling; suggest decoupling expiration from scanning to maintain clean separation of concerns.

1. Clarify Requirements

Ask about the use case: Is the scan read-only? What are the latency and consistency requirements? Are there multiple concurrent clients?

2. Analyze Trade-offs

Compare skipping (simpler, but leaves expired data) vs. evicting (reclaims space, but adds write overhead and potential contention).

3. Consider System Design Principles

Discuss separation of concerns, idempotency, and the impact on caching, replication, and transaction semantics.

4. Propose a Solution

Recommend an approach, such as skipping expired keys during scan and relying on a background eviction process, or conditionally evicting if the system supports it without side effects.

5. Address Implementation Details

Mention how to handle edge cases like concurrent writes, TTL precision, and monitoring for expired key accumulation.

Key Points to Mention

  • Performance impact: eviction during scan can increase latency and resource usage.
  • Consistency: skipping may return stale data if expiration is not strictly enforced.
  • Concurrency: evicting during scan can cause race conditions with other operations.
  • API design: read operations should ideally be free of side effects.
  • Alternative: use a dedicated background eviction process (e.g., lazy expiration or active expiration).
  • Trade-off between immediate space reclamation and operational simplicity.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Where should you store the expiry timestamp for each key: inline with the value, or in a separate structure like a min-heap ordered by expiry time?

Algorithms & Data StructuresSystem Design
Author's notes

Storing expires_at inline is obvious and I said that first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: are we optimizing for memory, read/write latency, or simplicity? Then compare inline storage (timestamp with each value) versus a separate min-heap (ordered by expiry) for operations like set, get, and expiry cleanup. Conclude with a hybrid recommendation, such as inline timestamps for per-key checks and a min-heap for efficient bulk expiry, tailored to the system's scale and access patterns.

Pro tip: Mention that a min-heap alone doesn't support O(1) deletion of arbitrary keys, so you'd need a hash map from key to heap node (or lazy deletion) to avoid O(n) scans—this shows you understand real-world implementation trade-offs.

1. Clarify requirements and constraints

Ask about expected read/write ratio, memory limits, latency SLAs, and whether expiry is passive (on access) or active (background cleanup). This determines which structure is optimal.

2. Analyze inline timestamp storage

Explain that storing expiry with the value gives O(1) access for per-key expiry checks and minimal memory overhead, but makes finding the next key to expire O(n) without additional indexing.

3. Analyze separate min-heap by expiry

Describe how a min-heap enables O(1) peek and O(log n) insert/delete of the earliest-expiring key, ideal for active expiry, but requires extra memory and careful synchronization with the main store.

4. Compare operations and trade-offs

Contrast set, get, delete, and expiry-scan complexities for both approaches, noting that inline is simpler and memory-efficient, while a heap excels at bulk expiry but adds complexity for arbitrary deletions.

5. Recommend a hybrid or context-specific solution

Propose storing expiry inline for per-key checks and maintaining a min-heap (with a key-to-heap-node map) for efficient background expiry, or choose one based on whether the system needs active or passive expiration.

Key Points to Mention

  • Time complexity of core operations: get, set, delete, and finding/removing expired keys
  • Memory overhead: inline timestamps add bytes per key; a min-heap adds a node per key plus pointers
  • Active vs. passive expiration: passive checks on access vs. background sweeper using a heap
  • Need for a secondary index (e.g., hash map from key to heap node) to support O(log n) deletion from the heap
  • Concurrency and synchronization: how to keep the heap and main store consistent under concurrent writes
  • Real-world examples: Redis uses inline expiry plus a sampling approach, while some systems use timing wheels or heaps for efficient expiry

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.