Skip to content

Commit 2f07c61

Browse files
committed
Updated with more info.
1 parent a7ab3c0 commit 2f07c61

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

Diff for: system_design/edge_cases.md

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
1+
# Scope out your requirements
2+
There is no secret sauce or one size fits all design for any problem.
3+
However, its good to point out constraints before beginning your design.
4+
The following list are some questions you should always ask for every system design interview to scope out your requirements and constraints.
5+
Keep in mind of the CAP theorem, as there is no single design that is 100% bulletproof for all cases.
6+
7+
- Volume of reads
8+
- Volume of writes
9+
- Volume of data stored
10+
- Complexity of data
11+
- Response time
12+
- Access patterns
13+
114
# 80/20 Rule
2-
Almost every service you are providing will have this 80/20 rule applied to it. The 80/20 rule means, 80% of the most used features will make up 20% of your possible services or 20% of your users generate 80% of the traffic.
15+
Almost every service you are providing will have this 80/20 rule applied to it.
16+
The 80/20 rule can be defined in many different ways, it usually means, 80% of effects come from 20% of causes.
317

4-
For example, Chrome browser, many people use it for the browsing, gmail, youtube, bookmarks, refresh, print feature, back button, etc... But the average user won't care much about the options, extensions, or the fact that you can open 10 tabs with one button etc...
5-
If you think of the problem this way, you can then focus a lot of your attention on the 20% of your services. How you can setup your system design around this 20%?
18+
For example, 80% of the most used features will make up 20% of your possible services or 20% of your users generate 80% of the traffic.
19+
Like the Chrome browser, many people use it for the browsing, gmail, youtube, bookmarks, refresh, print feature, back button, etc...
20+
But the average user won't care much about the options, extensions, or the fact that you can open 10 tabs with one button etc...
21+
If you think of the problem this way, you can then focus a lot of your attention on the 20% of your services.
22+
How you can setup your system design around this 20%?
623

724
Another case is that most of your traffic is concentrated in one area of your services, then you should separate these into two different architectures.
8-
For example, if an average user posts something on their feed, it may or may not be that important that your friends may get that new message 1 min from now or 5 mins from now. But if a famous celebrity were to post something, a lot more people will notice that feeds would come at different times if your design was setup this way. So this would become a real issue and one way to solve this is to dedicate a network of databases and applications for just the very famous or ones will over X million followers.
25+
For example, if an average user posts something on their feed, it may or may not be that important that your friends may get that new message 1 min from now or 5 mins from now.
26+
But if a famous celebrity were to post something, a lot more people will notice that feeds would come at different times if your design was setup this way.
27+
So this would become a real issue and one way to solve this is to dedicate a network of databases and applications for just the very famous or ones will over X million followers.
928

10-
Another case is that maybe 20% of your data is accessed by 80% of your users. You can then consider if it is possible to store that 20% into a memcache for high availability. While having a separate cache that would act more like a normal LRU cache for 80% of the data.
29+
Another case is that maybe 20% of your data is accessed by 80% of your users. You can then consider if it is possible to store that 20% into a memcache for high availability.
30+
While having a separate cache that would act more like a normal LRU cache for rest of the data.
1131

1232
The 80/20 rule is a great thing to think about after you have laid out your design. This is when you want to further optimize the design.
1333

1434
# Race Conditions
1535
Identify any part of your system that requires more than one component to share some piece of data.
16-
For example, if two services need to book a room at a hotel, there can be a scenario that two users want to book the same room at the hotel. You would need a locking service to block/hold any other requests for a particular room.
36+
For example, if two services need to book a room at a hotel, there can be a scenario that two users want to book the same room at the hotel. You would need a locking service to block/hold any other requests for a particular room until payment is successfully processed.
1737

1838
If you are making a web crawler, you need to keep track of visited webpages.
1939
Instead of allowing the web crawlers to manage the visited set, reverse the responsibilities and dedicate a component like a URL manager to distribute the URLs to the web crawlers while keeping track of the visited URLs.
40+
This eliminates any race conditions between crawlers and handled by one entity.
2041

21-
# Shut everything down
42+
# Fault Tolerance
2243
During the interview, generally a good interviewer will start asking the question of "What if this dies?".
2344
This is to move you to start thinking about single points of failures.
2445

2546
General responses would be using a master-slave architecture.
26-
However, there is always the question "What if both die?"
47+
However, there is always the question "What if both die?".
2748
This is generally the cases when a service that was processing a response, suddenly dies.
2849
Therefore, losing the request that was being processed.
2950

30-
You would then need to start moving your design into a more persistent state, so you can revive the system from scratch using the data stored. Or have a second component handle the responses and resend that response if it timesout.
31-
The problem is that latency of the response may slow due to the need in writing to disk for every response.
32-
This is generally a problem related to message queues stored in memory.
51+
You would then need to start moving your design into a more persistent state, so you can revive the system from scratch using the data stored.
52+
Another option is to have a second component handle the responses and resend that response if there is a timeout.
53+
However, latency of the response may slow due to the need to write to disk for each response or additional complexity.
3354

3455
# Avoid Tightly Coupled Architecture
3556
If you were making a financial account aggregator service like Mint.com.
@@ -41,6 +62,6 @@ All aggregators interact with a proxy server.
4162

4263
What you should not do, is have the same set of aggregators interact with different banks and credit card accounts.
4364
The role and responsibilities start getting tightly coupled at that point.
44-
Just duplicate each design, but dedicate a set of aggregators and message queues to only interact with one financial institution.
45-
This makes it easier for deployment when the API changes and less risk of the new change in breaking each other services'.
65+
Just duplicate each design, but dedicate each set of aggregators and message queues to only interact with one financial institution.
66+
This makes it easier for deployment when their API changes and less risk of the new change in breaking each other services.
4667
Also, future proofs your system when a financial institution is no longer around.

0 commit comments

Comments
 (0)