@rkenmi - Quick Numbers in Software Engineering Cheatsheet

Quick Numbers in Software Engineering Cheatsheet


A handy back of the envelope calculations guide and numbers you should remember!

Quick Numbers in Software Engineering Cheatsheet

0 Comments

Preface

Numbers

Data Types to Bytes
Size Tables
Time Tables
Time to Seconds
ISO8601
Requests
Availability
In sequence formula
In parallel formula
Latency to Remember
Back to Top

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 [231,231]. Up to ~4 billion numbers. Each byte has 8 bits, so 328=4
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 [263,263] 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 YYYY×10000+MM×100+DD and a four-byte integer for time packed as HH×10000+MM×100+SS. 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 100 1 byte
1,000 Thousand 103 1 KB (1 kilobyte)
1,000,000 Million 106 1 MB (1 megabyte)
1,000,000,000 Billion 109 1 GB (1 gigabyte)
1,000,000,000,000 Trillion 1012 1 TB (1 terabyte)
1,000,000,000,000,000 Quadrillion 1015 1 PB (1 petabyte)

Time Tables

Millisecond (10sec3) 1sec=1,000ms
Microsecond (10sec6) 1sec=1,000,000μs
Nanosecond (10sec9) 1sec=1,000,000,000ns

Time to Seconds

Hour Day Month Year
6060=3600 360024=86400 8640030=2592000 259200012=31104000
3600 secs approx. ~85k secs approx. ~2.5 million secs approx. ~30 million secs

ISO8601

Requests

Requests Requests per second
2.5 millionreq/month 1req/sec
86,400req/day 1req/sec

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 0.5ns
Branch misredirect 5ns
L2 cache reference (L1 is about 14x faster) 7ns
Mutex lock/unlock 25ns
Main Memory Reference (20x slower than L2 cache) 100ns
Very Fast
Compress 1 KB (i.e. with Zippy) 10,000ns 10μs
Send 1 KB over 1 Gbps network 10,000ns 10μs
Read 4 KB randomly from SSD 150,000ns 150μs 0.15ms
Read 1 MB sequentially from memory 250,000ns 250μs 0.25ms
Round trip within same datacenter 500,000ns 500μs 0.5ms
Read 1 MB sequentially from SSD (~1 GB/sec SSD, 4 times slower than RAM) 1,000,000ns 1,000μs 1ms
Somewhat fast
HDD seek (i.e. 7200 RPM disk drives) 10,000,000ns 10,000μs 10ms
Read 1 MB sequentially from 1 Gbps network 10,000,000ns 10,000μs 10ms
Read 1 MB sequentially from HDD 30,000,000ns 30,000μs 30ms
Send a packet CA -> Netherlands -> CA 150,000,000ns 150,000μs 150ms

Article Tags:
mathsystem designbytes