100%(1)100% found this document useful (1 vote) 211 views18 pages7 Algorithms To Know Before Your Next System Design Interview
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
08/08/2028, 04:21 77 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Levsl Up Coding
Game) Snin
Q y
Openinapp 7
7 Algorithms to Know Before Your Next System
Design Interview
® Arslan Ahmad - Follow
BO Pudiished'in Level up Coding
Emin read » Dec 21,2022
D tisten — *) Share
Get your next system design interview off to a great start.
7 Algorithms to Know Before Your next
System Design Interview.
Noeetit@a Had
es rasteres Tra He ste)
ee
ystee(iiePnt) | Heian?) | Hse HahDesPa) | Heetmmous Pa)
Consistent Hashing
Merkle Tree
{=} [Link]
In this post, we will discuss seven system design concepts that can be used to solve
design problems related to distributed systems. As these concepts can be applied to
all kinds of distributed systems, they become very handy during system design
interviews.
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa an.‘0808/2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
Here is the list of concepts we will be discussing:
1. Merkle Tree
2. Consistent Hashing
3. Read Repair
4. Gossip Protocol
5. Bloom Filter
6. Heartbeat
7. CAP and PACELC Theorems
Let's get started.
1. Merkle Tree
Used for identifying data inconsistencies between servers.
Merkle Tree
Background
Distributed systems maintain multiple copies of data on different servers (called
replicas) for fault tolerance and higher availability. To keep the data in syne among
all replica servers, the system needs an efficient mechanism to compare data
between two replicas. In a distributed environment, how can we quickly compare
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa ane8108/2029, 04:24 7 Algorthms to Know Before Your Nex! System Design Interview | by Arslan Ahmad | Level Up Cacing
two copies of a range of data residing on two different replicas and figure out
exactly which parts are different?
Definition
A replica can contain a lot of data. Naively splitting up the entire range to calculate
checksums for comparison is not very feasible; there is simply too much data to be
transferred. Instead, we can use Merkle trees to compare replicas of a range.
Solution
A Merkle tree is a binary tree of hashes, where each internal node is the hash of its
two children, and each leaf node is a hash of a portion of the original data.
Comparing Merkle trees is conceptually simple:
1. Compare the root hashes of both trees.
2. If they are equal, stop.
3. Recurse on the left and right children.
Ultimately, this means that replicas know exactly which parts of the range are
different, but the amount of data exchanged is minimized. The principal advantage
of a Merkle tree is that each branch of the tree can be checked independently
without requiring nodes to download the entire tree or the entire data set. Hence,
Merkle trees minimize the amount of data that needs to be transferred for
synchronization and reduce the number of disk reads.
The disadvantage of using Merkle trees is that many key ranges can change when a
node joins or leaves, at which point the trees need to be recalculated.
Examples
For anti-entropy and to resolve conflicts in the background, Amazon’s Dynamo uses
Merkle trees.
Details: [Link]
2. Consistent Hashing
Distributed systems use Consistent Hashing to distribute data across servers.
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa ane‘osioa2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
eg ee | cee 9
Hash range = 1-100
Number of Nodes = 4 ones
Number range per node = 100/4 Server? >
All data in the range 1-25 is stored
at Server 1 and so on.
Consistent Hashing ring
Consistent Hashing helps with two things:
1, It maps data to physical servers. Whenever the system wants to read or write
data, Consistent Hashing tells us which server holds the data.
2. It ensures that only a small set of keys move when servers are added or
removed.
More details: [Link]
3. Read Repair
When the data is replicated across multiple servers, Read Repair is used to push the
latest version of data to servers with older version.
Repair stale data during the read operation, since at that point, we can read data
from multiple servers to compare and find servers with stale data.
Details: [Link]
4. Gossip Protocol
Used for efficiently sharing state information between servers.
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa ane‘osfoa2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Cading
Every second each server exchanges information with one randomly selected server
1, 2,3, 8}
Server 5)
11,3,5)
“Server 2)
11,3, 5) —
24.81
Every second each server exchanges information about all the servers it knows about
11,2, 3,4, 5)
11,2,3, 4,5] a 1.2.3, 4,5)
11,2,9,4,5)
Gossip Protocol ([Link])
Each server keeps track of state information about other servers in the cluster and
gossips (i.e., shares) this information with one random server every second. This
way, eventually, each server gets to know about the state of every other node in the
cluster.
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa sie‘0808/2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
Details: [Link]
5. Bloom Filter
The Bloom filter data structure tells whether an element may be in a set, or
definitely is not. The only possible errors are false positives, ie., a search for a
nonexistent element might give an incorrect answer. With more elements in the
filter, the error rate increases. An empty Bloom filter is a bit-array of n bits, all set
to 0. There are also « different hash functions, each of which maps a set element to
one of the m bit positions.
* To add an clement, feed it to the hash functions to get k bit positions, and set
the bits at these positions to 1.
+ To test if an element is in the set, feed it to the hash functions to get k bit
positions.
+ Ifany of the bits at these positions is 0, the element is definitely not in the set.
+ Ifall are 1, then the element may be in the set.
Here is a Bloom filter with three elements P, 9, and & . It consists of 20 bits and
uses three hash functions. The colored arrows point to the bits that the elements of
the set are mapped to.
LX
D6 8 8 1:
x
ABloom filter consisting of 20 bits.
A Bloom filter consisting of 20 bits.
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa ane‘0808/2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
« The element x definitely is not in the set, since it hashes to a bit position
containing 0.
« Fora fixed error rate, adding a new element and testing for membership are
both constant time operations, and a filter with room for ‘n’ elements requires O
(n) space.
Details: [Link]
6. Heartbeat
Used for broadcasting the health status of a server.
Background
Ina distributed environment, data (or work) is distributed among servers. Such a
setup requires servers to know what other servers are part of the system in order to
route requests efficiently. Furthermore, servers should be able to tell if other
servers are up and running. In a decentralized environment, whenever a request
arrives at a server, the server should be able to decide which server is responsible
for entertaining that request. In this way, timely detection of server failure is
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 788108/2029, 04:24 Algorithms to Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Caging
crucial, enabling the system to take corrective action and move data (or work) to
another healthy server and stop the environment from deteriorating further.
Definition
Ina distributed environment, each server periodically sends a heartbeat message to
acentral monitoring server or other servers in the system to show that it is still alive
and functioning.
Solution
Heartbeating is one of the mechanisms for detecting failures in a distributed
system. If there is a central server, all servers periodically send a heartbeat message
to it. If there is no central server, all servers randomly choose a set of servers and
send them a heartbeat message every few seconds. This way, if no heartbeat
message is received from a server for a while, the system can suspect that the server
might have c
system can conclude that the server is not alive anymore and stop sending requests
to it and start working on its replacement.
shed. If there is no heartbeat within a configured timeout period, the
Example
Google File System (GFS) and HDFS use Heartbeating to communicate with each
other servers in the system to give instructions and collect state.
Details: [Link]
7. CAP and PACELC Theorems
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa
ane‘osroa2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
EWE sy ig
eed
CAP theorem
PACELC theorem
CAP and PACELC Theorems
With the help of these two theorems, distributed systems can choose a good balance
between Consistency, Availability, Partition Tolerance, and Latency.
Details: [Link]
Conclusion
— Practice these system design concepts to distinguish yourself from others!
— Learn more on these approaches in “Grokking the System Design Interview” and
“Grokking the Advanced System Design Interview.
— Follow me on Linkedin for tips on system design and coding interviews.
Read more on System Design and Coding Interviews:
Don't Just LeetCode; Follow the Coding Patterns Instead
Coding Interviews are getting harder to pass. To prepare for coding
interviews, you will need weeks, if not months of.
[Link]
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-éde21374ffa one08/08/2028, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Levsl Up Coding
‘System Design Interview Survival Guide (2023): Preparation
Strategies and Practical Tips
The 2023 system design interview playbook.
[Link]
System Design Interview Distributed Systems Programming —_—_Algorithms
S Gaon) OQ)
Written by Arslan Ahmad
9.7K Followers - Writer for Level Up Coding
Founder [Link] | Formally a software engineer @ Facebook, Microsoft, Hulu, Formulatrix |
Entrepreneur, Software Engineer, Writer.
More from Arslan Ahmad and Level Up Coding
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 101808/08/2028, 04:21 77 Algorithms lo Know Before Your Next System Design Interview | by Arsian Ahmad | Levsl Up Coding
Load Balancer
vs.
Reverse Proxy
vs.
API Gatewav
& Arstan Ahmad in Geek Culture
Load Balancer vs. Reverse Proxy vs. API Gateway
Understanding the Key Components for Efficient, Secure, and Scalable Web Applications.
12min read . May 17
@ sacob Bennett in Level Up Coding
Use Git like a senior engineer
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa we87082020, 04:21 "T Ngorits to Know Before Your Next Systm Design Interview | by Asian Ahmad | Level Up Coding
Git is a powerful tool that feels great to use when you know how to use it.
+ 4minread » Nov15, 2022
Sack Qar ot
© Gencay|. in Level Up Coding
5 ChatGPT plugins That Will put you ahead of 99% of Data Scientists
Elevate Your Data Science Game with ChatGPT Plugins
‘Tminread - Jul?
S504 Qa ae
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa rane‘osioa2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
12 Microservices Patterns | Wish
| Knew Before the Interview
& Arsian anmad in Level Up Coding
12 Microservices Patterns I Wish | Knew Before the System Design
Interview
Mastering the Art of Scalable and Resilient Systems with Essential Microservices Design
Patterns
13min read » May 16
a
SH22K Qs
¢ See all from Arslan Ahmad )
C ‘See all from Level Up Coding )
Recommended from Medium
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 1318‘oso82023, 04:21
‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Cading
a ee
@ The coding Diaries in The Coding Diaries
Why Experienced Programmers Fail Coding Interviews
A friend of mine recently joined a FAANG company as an engineering manager, and found
themselves in the position of recruiting for.
+ + Sminread » Nov2,2022
® 62x Q 129 ot
® Love sharma in ByteByteGo System Design Alliance
System Design Blueprint: The Ultimate Guide
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde2137étfa vane08/08/2028, 04:21 77 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Levsl Up Coding
Developing a robust, scalable, and efficient system can be daunting. However, understanding
the key concepts and components can make the...
+ + 9minread - Apr20
General Coding Knowledge
20stories - 167 saves
It's never too late or early to start something
‘stories . 87 saves
Coding & Development
Histories - 91 saves
ny Stories to Help You Grow as a Software Developer
19stories - 238 saves
& anthony [Link]
How to Practice LeetCode Problems (The Right Way)
thdr: You're doing it wrong. Use “The Six Steps” any time you practice LeetCode questions,
preferably with another person. Keep an...
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 1518‘0808/2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
+ + 13min read » May 10,2022
Hix Qe wi
Rate Limiter
Requests
a
—
> > >
®@ Ethiraj stinivasan in Bootcamp
The world of Rate Limit Algorithms
Rate limit algorithm is a mechanism used to control the rate of requests or messages being
sent or received by a system or service.
+ + 14min read » Marg
Ha Q wt
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 161808/08/2028, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arsian Ahmad | Levsl Up Coding
@ acob Bennett in Level Up Coding
Use Git like a senior engineer
Git is a powerful too! that feels great to use when you know how to use it.
+ 4minread - Nov15,2022
& sex Qar wi
LJ
| |)
@ ttussein Nasser
Postgres vs MySQL
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa we‘0808/2023, 04:21 ‘7 Algorithms lo Know Before Your Next System Design Interview | by Arslan Ahmad | Level Up Casing
The fundamental difference between the two popular databases
+ + 9minread - Feb6
om Qu
C See more recommendations: »)
hitps:[Link].conv7-algorthms-to-know-before-yournex-system-designinterview-dde21374tfa 1818