← Lyft Interview Insights

Lyft·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026Remote

Summary

Lyft software engineer interview with a meaty coding problem centered on building an in-memory key-value store from scratch. The problem had more moving parts than I expected and I spent way too long second-guessing the transaction design.

Questions Asked (1)

Q1

Design and implement an in-memory key-value database that supports SET, GET, DELETE, COUNT, BEGIN, ROLLBACK, and COMMIT commands, with average O(1) per operation and correct transactional semantics including nested transactions.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

The COUNT part is what tripped me up first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a design using a hash map for O(1) operations and a stack of transaction logs for nested transactions. Walk through the implementation of each command, emphasizing how BEGIN, ROLLBACK, and COMMIT maintain atomicity and isolation.

Pro tip: Mention that you would use a stack of transaction logs where each log records the previous value of modified keys, enabling O(1) rollback by reverting changes in reverse order. Also, highlight that nested transactions require careful handling of commit propagation to parent transactions.

1. Clarify Requirements and Constraints

Ask about expected data types, concurrency requirements, and whether transactions need isolation from other clients. Confirm that average O(1) is required and that nested transactions must be supported.

2. Design Core Data Structures

Propose a hash map for the main key-value store and a stack of transaction logs for managing nested transactions. Each log entry should store the key and its previous value (or a tombstone for new keys).

3. Implement Basic Commands (SET, GET, DELETE, COUNT)

Explain how each command operates in O(1) average time: SET updates the map and logs the old value if in a transaction; GET retrieves from the map; DELETE removes the key and logs; COUNT maintains a counter or returns the map size.

4. Implement Transaction Commands (BEGIN, ROLLBACK, COMMIT)

Describe how BEGIN pushes a new empty log onto the stack. ROLLBACK pops the top log and reverts all changes in reverse order. COMMIT merges the top log into the parent log (if any) or applies changes permanently.

5. Analyze Complexity and Edge Cases

Discuss time and space complexity: O(1) average for all operations, O(k) for rollback/commit where k is the number of changes in the transaction. Address edge cases like nested rollback, commit with no active transaction, and handling of deleted keys.

Key Points to Mention

  • Use a hash map for O(1) average-time key-value operations.
  • Maintain a stack of transaction logs to support nested transactions.
  • Each log entry stores the key and its previous value (or a marker for non-existence) to enable rollback.
  • ROLLBACK reverts changes in reverse order to maintain consistency.
  • COMMIT merges the current transaction's log into the parent transaction or applies changes if no parent.
  • COUNT can be maintained as a separate counter or derived from the map size, ensuring O(1).

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