Skip to content
Dhruvgiri Goswami
All writing

Why your business app feels slow, and the three fixes that matter

Dhruvgiri Goswami4 min readPerformanceMongoDBRedis

When a client tells me their system is slow, they rarely mean the whole thing. They mean one screen: the report the owner opens every morning, or the order list the sales team keeps refreshing. It takes four seconds, and everyone has quietly learned to wait.

Below is roughly what happens when a report like that loads. Try the three switches.

Opening the monthly sales report

0 ms

Optimisations
Illustrative timings for a typical setup, not a benchmark.

The point of the demo is the shape, not the exact numbers. In almost every slow system I have looked at, one step takes most of the time, and it is rarely the one people guess.

Measure before you touch anything

The first job is finding the slow step, not fixing anything. Three quick checks cover most cases:

  1. Open the browser’s developer tools (F12), go to the Network tab and reload the slow page. Sort by time. If one API call takes 3 seconds and everything else takes 50 ms, you know where to look.
  2. Log how long each request takes on the server. In NestJS or Express, a few lines of middleware that print the route and the time taken will show you the worst offenders within a day of normal use.
  3. Turn on the database’s slow query log. MongoDB’s profiler records every query slower than a threshold you set. I wrote about finding slow MongoDB queries separately.

If you skip this step, you end up adding a cache to a page that was slow because of a 4 MB image.

Fix 1: the database query

Most of the time, the slow step is a query that reads far more data than it returns. A monthly sales report that scans every order the company has ever taken will get slower every single day, because the collection keeps growing.

The fix is often one line: an index that matches how the query filters and sorts.

// orders.schema.ts
// The report filters by company and date range, newest first.
OrderSchema.index({ companyId: 1, createdAt: -1 });

With the index, the database jumps straight to the right company and month instead of reading everything. On a collection with a few hundred thousand orders, that can turn seconds into milliseconds.

Other common culprits in the same family:

  • Loading related records one at a time in a loop (the “N+1” problem). Fetch them in one query with $in, or with a single aggregation.
  • Returning whole documents when the screen needs three fields. Use a projection.
  • Counting or summing in application code after loading everything. Let the database do it with an aggregation pipeline.

Fix 2: caching, but only after the query is fixed

Redis can make a report almost instant by keeping the finished result in memory. It is a great second step and a bad first one. A cache in front of a slow query only hides the problem until the cache expires, and then the first person in the morning waits even longer than before.

Fix the query, then cache it if it is still worth it. Good candidates are results that many people read and that change rarely: dashboards, lists of products, settings. My notes on Redis caching in NestJS cover the details, including how to keep the cache from serving stale numbers.

Fix 3: static files should never touch your server

The app’s JavaScript, CSS, fonts and images are the same for every user. There is no reason for your server to send them. Put them behind a CDN such as Cloudflare and let the nearest edge location serve them, with long cache lifetimes and file names that change when the content changes (most build tools do this for you, e.g. app.4f3a9c.js).

Two other quick wins in the same area:

  • Compress responses. Nginx can gzip or Brotli-compress JSON and text. A 600 KB JSON response often shrinks to under 80 KB.
  • Resize images before upload. A 4000 px phone photo shown at 300 px wide is pure waste. Convert to WebP or AVIF at the size you display.

What usually does not matter

People often reach for a bigger server first. Unless the server’s CPU is actually busy (check with htop), more cores will not make a slow query faster. Moving to a different framework or database almost never helps either. The boring fixes above solve the large majority of “the app is slow” complaints, and they cost a few hours, not a rewrite.

A short checklist

  • Find the slowest request with browser tools and server timing logs
  • Check that request’s database queries with explain()
  • Add indexes that match the filters and sort order
  • Remove N+1 loops and return only the fields you need
  • Cache results that are read often and change rarely
  • Serve static files from a CDN with long cache headers
  • Compress responses and resize images

If your team has learned to wait for a screen, it is almost always fixable. Tell me which one and I will tell you where the time goes.