annotate async_multi_threads/README.md @ 69:551d9fc0a2ba

Updated wrong names.
author June Park <parkjune1995@gmail.com>
date Thu, 25 Dec 2025 20:07:46 -0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 # Distributed Cache (Focus: Hashing & System Logic)
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 - Question: Implement a Cache Router
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 Level 1 (Easy - Modulo Hashing): Write a function that maps a key (string) to one of N servers.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 Task: Implement getServerIndex(key, serverCount).
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 Expected Logic: Simple hash modulo: hash(key) % serverCount.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 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).
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
13 Level 2 (Medium - Consistent Hashing): Solve the remapping problem. Implement a ConsistentHash class.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
14
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
15 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.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
16
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17 Goal: Prove that adding a server only requires remapping the keys that fall between the new server and its predecessor.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 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).
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 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).
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 Goal: Distribute load more evenly and handle "hot spots" better.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 ---
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
26
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 Questions:
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
28
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
29 - Async
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
30 - Threads
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
31 - DB
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 - Cache
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
33 - KV
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
34 - Distribution
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
35
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
36
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
37 ---
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
38
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
39 FE
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
40
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
41 - Fetching URL
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
42 - Storing it as useMemo and what not.
551d9fc0a2ba Updated wrong names.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
43