Mercurial
view grok_interview/README.md @ 58:ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 20 Dec 2025 09:33:15 -0800 |
| parents | 68fa88ac73fe |
| children |
line wrap: on
line source
# Distributed Cache (Focus: Hashing & System Logic) - Question: Implement a Cache Router Level 1 (Easy - Modulo Hashing): Write a function that maps a key (string) to one of N servers. Task: Implement getServerIndex(key, serverCount). Expected Logic: Simple hash modulo: hash(key) % serverCount. Critique: The interviewer will ask, "What happens to the existing keys if we add one server (change N to N+1)?" (Answer: Almost all keys get remapped, causing a massive cache miss storm). Level 2 (Medium - Consistent Hashing): Solve the remapping problem. Implement a ConsistentHash class. Task: Map servers to points on a circle (0 to 360 degrees or a large integer range). Map keys to the same circle. A key belongs to the first server it encounters moving clockwise. Goal: Prove that adding a server only requires remapping the keys that fall between the new server and its predecessor. Level 3 (Hard - Virtual Nodes): The servers have uneven capacity, or the data distribution is skewed (some segments of the ring have way more keys). Task: Modify the class so that each physical server exists at multiple points on the ring (e.g., "Server A" is at positions 10, 150, and 290). Goal: Distribute load more evenly and handle "hot spots" better. --- Questions: - Async - Threads - DB - Cache - KV - Distribution --- FE - Fetching URL - Storing it as useMemo and what not.