Skip to content
StackDecode
System Design
4. Database FundamentalsAnimated

B-Tree Indexing

A balanced tree that keeps sorted keys for fast lookups and ranges.

The idea

B-trees keep all leaves at the same depth, so any lookup takes few disk reads.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

App serversPrimary (writes)Replica 1 (read…Replica 2 (read…
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

Step one: add indexes and cache.

step:
1/4
at:
App servers
1/7

The green dot is a request moving through the system.

Step by step

  1. 1Start at the root
  2. 2Compare keys to pick a child
  3. 3Descend to a leaf
  4. 4Read the row or range

Where it is used

Default index in most databases.

Watch out for

Random inserts cause page splits.

Related