Bugpit

Lessons › From one user to millions

People you may know

A social app with 5,000 req/s. 4% are "people you may know" lookups: 200 a second, each walking friends of friends. In SQL that's a join on a join, and each one takes over a second.

Play this level

Free with an account. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

SQL can answer this, but each hop is another join over a huge table, and each hop multiplies the rows. Two hops is slow. Three is a bad day.

A graph database such as Neo4j or Neptune stores each link next to the thing it links. A hop is a short step, so the cost depends on how much you walk, not on the size of the table.

It's a specialist tool. Use it when the links between things are the point, like friends or fraud rings, and keep plain lookups in your normal database.

What you have to achieve

5,000 requests a second at the busiest hour, 2% of them writes.

What you learn

The database calmed down the moment those lookups moved. Keeping the graph up to date is real work that isn't shown here: you'd feed it from a stream, just like a search index. Its speed here is a starting guess, because it depends on how far each query walks.

Check yourself

Why are friends of friends lookups slow in SQL?

Show the answer

Each hop is another join, and each multiplies the rows. Two hops is a join on a join over a huge table. A graph database makes each hop a short step.

When is a graph database the right tool?

Show the answer

When the links between things are the point. Friends and fraud rings are about links. Keep plain lookups in your normal database.

Try it yourself

More in From one user to millions

← SQL that grows by itself Ready for launch →