← Google Interview Insights

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

Senior
May 2026

Summary

Google system design round for a software engineer role, focused entirely on a single meaty log management problem. The question had a lot of moving parts and I spent most of the time just trying to nail down the data model before even touching complexity targets.

Questions Asked (1)

Q1

Design a log management component that supports prioritized eviction under storage constraints. It needs a global cap on total log records, optional per-file caps, an addLog API that auto-evicts the least important logs when limits are hit (factoring in both priority and recency), plus query and capacity APIs. Target O(1) or amortized O(1) to find a deletion candidate and O(log n) per insert or eviction.

System DesignAlgorithms & Data StructuresData Modeling
Author's notes

This one took me a while to even decompose properly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a data structure that combines a hash map for O(1) access with a priority queue (heap) for efficient eviction. Explain how to handle global and per-file caps, and how to compute a composite score for eviction that balances priority and recency. Finally, discuss trade-offs and potential optimizations.

Pro tip: Mention that you would use a lazy deletion strategy in the heap to avoid O(n) removals, and that you would periodically rebuild the heap to maintain performance. This shows awareness of real-world implementation challenges.

1. Clarify Requirements and Constraints

Ask about expected scale, read/write patterns, and whether priorities are static or dynamic. Confirm that eviction should consider both priority and recency, and that per-file caps are optional.

2. Design Core Data Structures

Propose a hash map from log ID to log record for O(1) access, and a min-heap keyed by an eviction score (e.g., priority + timestamp) to find the least important log in O(1) amortized. For per-file caps, maintain a separate heap per file or a global heap with file filtering.

3. Define Eviction Policy and Scoring

Explain how to compute the eviction score: higher priority means less likely to evict, and more recent logs are less likely to evict. Use a weighted sum or lexicographic ordering. Discuss how to handle updates to priority or recency (e.g., lazy updates).

4. Implement AddLog and Eviction Logic

On addLog, insert into hash map and heap, then check global and per-file caps. If exceeded, pop from heap until under cap, removing from hash map. Use lazy deletion: mark evicted logs and skip them when popped.

5. Analyze Complexity and Trade-offs

Insert: O(log n) for heap push. Eviction: O(log n) per eviction (amortized O(1) if using lazy deletion and occasional rebuild). Query: O(1) for ID lookup, O(k) for range queries. Discuss memory overhead and alternatives like balanced BSTs.

Key Points to Mention

  • Use of a min-heap with a composite key (priority, timestamp) to efficiently find the least important log.
  • Lazy deletion to avoid O(n) removal from the heap when a log is evicted or updated.
  • Handling per-file caps by maintaining separate heaps or a global heap with file-based filtering.
  • Amortized O(1) eviction candidate finding via heap top, with O(log n) insert and eviction.
  • Trade-offs between strict O(1) and O(log n) operations, and potential need for periodic heap rebuilds.
  • Consideration of thread safety and concurrency if the component is used in a multi-threaded environment.

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