Updated on January 21, 2024
Preface
This article is a cheatsheet and a collection of tips/tricks for doing back of the envelope calculations.
Numbers
Data Types to Bytes
Note: keep in mind that these are general estimates. Depending on the language that implements them, the actual size stored in memory may vary.
Data Type | Byte(s) | Explanation |
CHAR | 1-4 bytes | 1 byte is enough to cover all the characters in ASCII and then some (1 byte = 255 character choices). Some languages that allow Unicode characters (144,697 character choices) will have to allocate more bytes per character, so some languages may use up 2-4 bytes rather than just 1. |
BOOL | 1 byte | True or False state can technically be represented by 1 bit, but the CPU can't address anything smaller than a byte. |
INT | 4 bytes | Decimals range from . Up to ~4 billion numbers. Each byte has 8 bits, so |
BIGINT | 8 bytes | It uses twice the number of bits as INT and doubles the ranges of INT, so it is called a BIGINT. Decimals of range can now be stored. |
FLOAT | 4 bytes | Same number of bytes as INT. In SQL, precision is supported up to 0 to 23 decimal places. Single precision. |
DOUBLE | 8 bytes | It uses twice the number of bits as FLOAT, so its called a DOUBLE. FLOAT has accuracy issues due to its limited floating point precisions that can't be widely represented under 4 bytes. |
DATETIME | 8 bytes | Contains date and time. A four-byte integer for date packed as and a four-byte integer for time packed as . Some implementations make this size more compact (down to 5 bytes in newer versions of SQL) but 8 bytes is a reasonable estimate for a DATETIME value. |
Size Tables
Pre-requisites: See the chart here for a quick primer on numbers.
Number (numerical) | Number (english) | Power | Byte |
1 | One | 1 byte | |
1,000 | Thousand | 1 KB (1 kilobyte) | |
1,000,000 | Million | 1 MB (1 megabyte) | |
1,000,000,000 | Billion | 1 GB (1 gigabyte) | |
1,000,000,000,000 | Trillion | 1 TB (1 terabyte) | |
1,000,000,000,000,000 | Quadrillion | 1 PB (1 petabyte) |
Time Tables
Millisecond () | |
Microsecond () | |
Nanosecond () |
Time to Seconds
Hour | Day | Month | Year |
3600 secs | approx. ~85k secs | approx. ~2.5 million secs | approx. ~30 million secs |
ISO8601
Requests
Requests | Requests per second |
This is all you need to know really. There are 2.5 million seconds in 1 month. This means that with 1 request per second, you have 2.5 million requests in that whole month.
Most request counts (for a month) usually range from millions to billions, so having this back-of-the-envelope formula should get you started for easy conversions.
Availability
99.9% availability - three 9s
Duration | Acceptable downtime |
Downtime per year | 8h 45min 57s |
Downtime per month | 43m 50s |
Downtime per week | 10m 5s |
Downtime per day | 1m 26s |
99.99% availability - four 9s
Duration | Acceptable downtime |
Downtime per year | 52min 36s |
Downtime per month | 4m 23s |
Downtime per week | 1m 5s |
Downtime per day | 9s |
In sequence formula
Overall availability decreases when two components with availability < 100% are in sequence:
Availability (Total) = Availability (Foo) * Availability (Bar)
In parallel formula
Overall availability increases when two components with availability < 100% are in parallel:
Availability (Total) = 1 - (1 - Availability (Foo)) * (1 - Availability (Bar))
Latency to Remember
These numbers from System Design Primer is a good reference sheet to remember when designing systems.
Actions | Nanoseconds | Microseconds | Milliseconds |
Blazing Fast | |||
L1 cache reference | |||
Branch misredirect | |||
L2 cache reference (L1 is about 14x faster) | |||
Mutex lock/unlock | |||
Main Memory Reference (20x slower than L2 cache) | |||
Very Fast | |||
Compress 1 KB (i.e. with Zippy) | |||
Send 1 KB over 1 Gbps network | |||
Read 4 KB randomly from SSD | |||
Read 1 MB sequentially from memory | |||
Round trip within same datacenter | |||
Read 1 MB sequentially from SSD (~1 GB/sec SSD, 4 times slower than RAM) | |||
Somewhat fast | |||
HDD seek (i.e. 7200 RPM disk drives) | |||
Read 1 MB sequentially from 1 Gbps network | |||
Read 1 MB sequentially from HDD | |||
Send a packet CA -> Netherlands -> CA |