How to Calculate Performance or Capacity of System
How to Calculate Performance or Capacity of System
While developing a system, it's common to consider the system's performance or capacity. For high levels of estimation, I find "Back-Of-The-Envelope" technique to be quite helpful.
You must have a solid understanding of scalability, the power of two, latency numbers, and availability numbers in order to use the aforementioned technique.
Let's start by discussing this on a high level.
- Power of Two - Even though dealing with distributed systems can result in large data volumes, calculations ultimately come down to the fundamentals. It is crucial to understand the data volume unit utilising power of two in order to achieve the correct value following calculations. A byte, for example, is a series of 8 bits.
Points to take away from this is below
- Memory(application memory) is fast but the disk is slow.
- Avoid reading from disk if possible.
- Simple compression algorithms are way faster.
- Compress data before sending it to over the network. (Mark this as very good practice)
- Data Centers are usually in different Geo regions and they takes times to sends data between them.
- Availability Numbers - A system's capacity to function continuously for a desired extended length of time is known as high availability. In terms of percentage, high availability is defined as a service that is available 100% of the time. 99% to 100% of services in this world fall under this range.
A service level understanding A service provider is commonly referred to by the acronym SLA. This is a contract that you and the service provider have made.
Examples of cloud service providers who set their SLAs at 99.99% or above include Amazon, Google, and Microsoft. In the past, uptime was expressed as nines. The better, the more nines.
For making this more clear let's do one Exercise.
Estimate Twitter QPS & Storage requirements
- Assumptions:
- 300 million monthly active users.
- 50% of users use Twitter daily
- Each user posts 2 tweets per day on an average.
- 10% of tweets contains media.
- Data is stored for 5 years.
Calculation:
QPS Query per Second estimation will be
- DAU(daily active users)= 300 million * 50%= 150 million
- Tweets QPS = 150 million * 2 tweets / 24 hours / 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 1MB
- Media storage: 150 millions * 2 * 10% * 1 MB= 30 TB per day
- 5- years media storage: 30 TB * 365 * 5= ~55 PB 💡