Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages

Help for owners

My API takes too long to answer

Short answer

An API is slow when the server spends its time on database queries, calls to other services, or too little memory. web.dev suggests most sites aim for a time to first byte of 0.8 seconds or less. Measure which requests are slow and when before changing anything.

  • Written for business owners
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Does this sound like your situation?

  • The app shows a spinner for many seconds.
  • Some requests time out, especially at busy hours.
  • It was fast when there were fewer users.
  • The screens that list lots of data are the slowest.
  • My developer says the server needs to be bigger.

Why does this happen?

  1. The database does too much work

    Missing indexes, queries run in loops, and large lists loaded at once make each answer take longer as data grows.

  2. Locks make requests wait

    When one operation holds a table or row, other requests wait behind it until they time out.

  3. A proxy gives up before the app answers

    A web server in front of the API closes a request that takes too long and shows a timeout error.

  4. There is a measurable target

    web.dev says TTFB is the time to the first byte of a response, and gives 0.8 seconds or less as good and over 1.8 seconds as poor. It says reducing latency in connection setup and on the backend can lower it.

What can I do about it today?

  1. Note which requests are slowWhich screen, which action, at what time. Patterns point to the cause.
  2. Check whether it is slow for everyoneTry on another network and device, so the cause is not just one connection.
  3. Do not buy a bigger server yetA bigger server costs more and may not help if the cause is a query.
  4. Note when it got worseA release, a new customer or a data import often lines up with it.
  5. Do not restart the server repeatedlyIt hides the symptom and loses information an engineer needs.

When should I bring someone in?

  • Requests time out for paying customers.
  • It gets worse as your data grows.
  • Your developer cannot say where the time goes.

How do I handle it?

  1. Measure firstI record how long each request takes and where that time is spent.
  2. Look at the slowest fewA handful of requests usually cause most of the delay.
  3. Fix the causeQueries, indexes, caching or timeouts are changed one at a time, and each change is measured.
  4. Keep it measuredA simple dashboard shows if it slows again.

The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.

What do owners ask about this?

Is the app slow or the API?

I check both. A screen can be slow because of the app and not the server.

What is a good response time?

web.dev suggests most sites aim for a TTFB of 0.8 seconds or less. It is a rough guide and not a promise.

Will caching fix it?

Sometimes. It helps for repeated reads, not for slow writes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Found a mistake? Tell me.

For your developer: the technical fixes

Next step

Want this off your desk?

Send me a few lines on where things stand. I reply within 24 hours.