cloudpatterns.appClassroomKatasWhiteboardBlog

Relational databases & indexes

Lesson~13 minStep 1 of 11
  1. Watch (current)
  2. Predict
  3. Explore
  4. Name the parts
  5. Explain
  6. Explain 2
  7. Explain 3
  8. Explain 4
  9. Explain 5
  10. Check
  11. Wrap up

Meet Ledger, an app for sharing expenses in a group — a flat, a trip, a team lunch. Each group keeps a running list of expenses and who owes whom. Everything lives in one relational database.

When groups were small, the group page opened instantly. Now some groups have thousands of expenses, the table holds millions, and the page has become sluggish. Watch 300 group pages a second, with 20 new expenses added a second alongside.

A group page takes about 25 ms: 5 ms in the Ledger API, 20 ms in the database. To find one group's expenses, the database reads the expenses table row by row and checks each one — a **full scan**. Each scan holds a connection for those 20 ms, so about 6 of the pool's 10 are busy. (A real scan gets slower as the table grows.)