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.
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?
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.
Technical detail: batchUpdate inserts one row at a time on MySQL
Locks make requests wait
When one operation holds a table or row, other requests wait behind it until they time out.
Technical detail: A statement waited for a lock held by another transaction and gave up (error 1205)
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.
Technical detail: nginx gives up waiting for the app and returns 504
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.
Confirmed by web.dev
What can I do about it today?
- Note which requests are slowWhich screen, which action, at what time. Patterns point to the cause.
- Check whether it is slow for everyoneTry on another network and device, so the cause is not just one connection.
- Do not buy a bigger server yetA bigger server costs more and may not help if the cause is a query.
- Note when it got worseA release, a new customer or a data import often lines up with it.
- 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?
- Measure firstI record how long each request takes and where that time is spent.
- Look at the slowest fewA handful of requests usually cause most of the delay.
- Fix the causeQueries, indexes, caching or timeouts are changed one at a time, and each change is measured.
- 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
jdbcTemplate.batchUpdate() takes seconds for a few thousand rowsbatchUpdate inserts one row at a time on MySQLERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transactionA statement waited for a lock held by another transaction and gave up (error 1205)504 Gateway Time-outnginx gives up waiting for the app and returns 504Route handler stops after a fixed number of seconds on production but not locallyA Next.js route handler is cut off after a fixed time