CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION

Power of two

A byte is a sequence of 8 bits. An ASCII character
uses one byte of memory (8 bits).

CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION_第1张图片

Latency numbers every programmer should know

in 2010
CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION_第2张图片

CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION_第3张图片
CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION_第4张图片
By analyzing the numbers in Figure 2-1, we get the following conclusions:
• Memory is fast but the disk is slow.
• Avoid disk seeks if possible.
• Simple compression algorithms are fast.
• Compress data before sending it over the internet if possible.
• Data centers are usually in different regions, and it takes time to send data between them.

Availability numbers

A service level agreement (SLA) is a commonly used term for service providers. This is an
agreement between you (the service provider) and your customer, and this agreement
formally defines the level of uptime your service will deliver
CHAPTER 2: BACK-OF-THE-ENVELOPE ESTIMATION_第5张图片

Example: Estimate Twitter QPS and storage requirements

Please note the following numbers are for this exercise only as they are not real numbers
from Twitter.
Assumptions:
• 300 million monthly active users.
• 50% of users use Twitter daily.
• Users post 2 tweets per day on average.
• 10% of tweets contain media.
• Data is stored for 5 years.
Estimations:
Query per second (QPS) estimate:
• Daily active users (DAU) = 300 million * 50% = 150 million
• Tweets QPS = 150 million * 2 tweets / 24 hour / 3600 seconds = ~3500
• Peek QPS = 2 * QPS = ~7000
We will only estimate media storage here.
• Average tweet size:
• tweet_id 64 bytes
• text 140 bytes
• media 1 MB
• Media storage: 150 million * 2 * 10% * 1 MB = 30 TB per day
• 5-year media storage: 30 TB * 365 * 5 = ~55 PB

Tips

Rounding and Approximation
Write down your assumptions
Label your units. When you write down “5”, does it mean 5 KB or 5 MB?
Commonly asked back-of-the-envelope estimations: QPS, peak QPS, storage, cache,
number of servers, etc. You can practice these calculations when preparing for an
interview.

你可能感兴趣的:(System,Design,系统架构)