DEV Community

Why Your API Feels Slow (It’s Not Your Backend)

Do you know that your system is not slow just because of the language that you're using, or even the framework? Sometimes it's your database, because it's reading every single row just to find one record. So how do we fix that?
Number 1: indexing. Think of an index like the index at the back of your book. Without it, your database will be scanning row by row by row by row until it finds what you asked for. With an index, it gets a faster path directly to your data, which is easier. Mbona uchoke your database?
Number 2: pagination. If you have 1 million users—now why, explain to me why—would you be fetching all 1 million of them? Fetch 70. Hiyo 70 ingine, pole pole, you know? Number 3: caching. If 1,000 users keep asking for the same data, you are not supposed to be hitting your database every single time. Just store the frequently requested results in a fast cache. Like Redis, and serve them from there. And finally, partitioning. When a table becomes massive, split it into logical sections. For example, orders from January, March, February, June. So instead of the database working with a giant table, it only works with a particular section, the only relevant one.

The idea is very simple: a fast database is one which touches less data. Si yenye kona—please. Less data, faster responses

Top comments (0)