May 30, 2026 · 178 views
Making a giant category tree open instantly
Thousands of nested categories, and it has to feel instant. Lazy loading to the rescue.
The marketplace has a category tree — think thousands of nested categories, "Electronics → Mobiles → Accessories → Chargers → ...". The first version loaded the whole thing up front. On my machine, fine. With the real dataset, the page just sat there thinking.
Loading a giant tree nobody fully expands is wasteful. Most users open two or three branches and move on.
So I made it lazy. Each node only fetches its children when you actually open it, and once fetched it's cached, so reopening is instant. Expanding any node is O(1) from the user's side — it doesn't care how big the tree is, only about the branch in front of them.
Then for people who know exactly what they want, I added server-side search in Express. Instead of shipping the whole tree to the browser and filtering there, the server does the lookup and returns just the matching path. Type "charger", get the branch, done.
The whole thing went from "please wait" to "oh, that was instant". Same data, completely different feel — because we stopped pretending the user needs everything at once.
Most performance wins aren't clever algorithms. They're just not doing work nobody asked for.