Start free trial
Start free trial Log in

14-day free trial. No credit card.

Laravel API latency: targets, tracking and fixes

Latency targets for Laravel JSON APIs, and how to track each endpoint's p95 and find what slows it down.

  • Guide
  • 2 min read

What's a good Laravel API latency target and how do I measure it?

For UI-blocking read endpoints target p95 under 200ms (good), with 200-500ms acceptable. Write endpoints under 500ms. Measure by grouping requests by route pattern (/api/orders/{id}) and computing percentiles per endpoint. Use a per-request trace view to find which span (DB query, external HTTP, cache call) ate the budget on slow instances. Laravel's nightwatch package captures all this; NightOwl and Nightwatch Cloud surface it per-endpoint.

Updated

With a web page, the browser papers over a lot: a spinner, a skeleton screen, a progressive render all make 500ms feel acceptable. An API has none of that. The thing on the other end is a machine that blocks until you answer, often inside a chain of three more calls, and every millisecond you spend lands directly in someone else's UX budget. That's why API latency targets are tighter than page targets, and why you judge an endpoint by the p95 its consumers see rather than by how fast it feels.

Latency targets by endpoint class

Endpoint type Good p95 Acceptable Problem
Auth (login, token refresh)< 200ms200-500ms> 500ms
UI-blocking read< 200ms200-500ms> 500ms
Search / filter< 300ms300-500ms> 500ms
Write (create / update)< 500ms500ms-1s> 1s
Background receipt (webhook)< 500ms500ms-2s> 2s

Why API latency is tighter than page latency

Three reasons:

  1. No perceptual masking. A browser showing a loading spinner at 500ms feels fine. A mobile app waiting on your API at 500ms feels janky.
  2. Chained calls. A single screen in a client app often fires 3-5 API calls. Made one after another at 200ms each, they add up to 600-1000ms of perceived latency.
  3. Consumers can't batch for you. A web server can render server-side and send one response; a consumer SDK makes calls one at a time unless you offer batching endpoints.

Middleware for API-specific timing context

app/Http/Middleware/ApiTiming.php

php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class ApiTiming
{
    public function handle(Request $request, Closure $next): Response
    {
        $start = hrtime(true);
        $response = $next($request);
        $durationMs = (hrtime(true) - $start) / 1e6;

        $response->headers->set('Server-Timing', 'total;dur='.round($durationMs, 1));

        return $response;
    }
}

Attach it to your API routes in bootstrap/app.php with $middleware->api(append: [ApiTiming::class]) inside withMiddleware(). Browser dev tools read the Server-Timing header (Chrome shows it on a request's Timing tab in the Network panel), which helps consumer-side debugging without exposing full trace data.

Per-endpoint trace drilldown

For a slow endpoint:

  1. Open the requests dashboard, filter to the route pattern
  2. Use the ≥P95 filter (or ≥P99) to list the route's slow requests
  3. Open a slow request's trace view
  4. Identify the dominant span, usually a DB query or outgoing HTTP call
  5. Fix that one thing (eager load, add index, move to async) and watch p95 drop

See our related guides: slow query monitoring, N+1 detection, outgoing HTTP tracking.

Budget for network

A consumer in Europe calling your US-East API can spend 70ms or more on each network round trip, before TLS setup. That's budget you can't compress with code. If your end-to-end API SLO is 300ms and network is 100ms, your server-side budget is 200ms. Plan accordingly.

Per-endpoint P95 on your own API traffic

NightOwl groups your API requests by route pattern, with Avg and P95 per endpoint and P99 on the route page. Filter an endpoint to its requests at or above P95, then open one to see which query or outgoing call held it up.

No credit card needed.

Terminal
composer require nightowl/agent
php artisan nightowl:install
php artisan nightowl:agent

Frequently asked questions

Anything else, write to support@usenightowl.com

What's a good latency target for a Laravel JSON API?

Tighter than page renders because consumer SDKs expect snappy responses. UI-blocking read endpoints: p95 under 200ms is good, 200-500ms is acceptable. Write endpoints: under 500ms. Above 500ms for any read endpoint feels slow to consumer-side developers, especially in mobile and SPA clients with their own UX latency budgets.

Why is API latency different from web page latency?

Consumers are machines, not browsers. A machine doesn't render anything while waiting; it just blocks. API calls are often chained (one SDK call triggers 3 more), so latency compounds. API latency also shows up directly in the consumer's UX: a slow /api/orders lookup is a slow order page on their frontend.

How do I measure API latency per endpoint?

Your APM groups requests by route pattern (/api/orders/{id}) rather than raw URL. Track p50, p95, p99 per endpoint over time. For Laravel with the nightwatch package, routes are grouped automatically. NightOwl computes exact percentiles from the raw per-request durations for short windows and estimates them from histogram rollups (DDSketch, within 1%) for wide ones. See our slow endpoints and p95 latency guides for specifics.

Should I include network latency in my API latency budget?

Depends on who owns the budget. For API SLO purposes (what you promise consumers), measure from the consumer's perspective (includes network). For internal bottleneck hunting, measure server-side only (where your code controls). As a starting budget, set aside around 100ms for the network (it varies by region) and give the rest to server-side work.

How do I find which query in a slow API endpoint is the culprit?

Per-request trace view. Any APM that records per-span detail (DB queries, cache calls, outgoing HTTP) shows you exactly which span ate the latency budget. A /api/orders/{id} at p95 2s with 1.8s spent in one SELECT FROM orders JOIN order_items points at a missing index or a bad plan for that join. An N+1 looks different: many copies of the same small query. NightOwl's request drilldown renders this waterfall, colours repeated SQL, and lists it on a Duplicates tab.

Does API versioning affect latency monitoring?

Yes. Version-prefix routes (/v1/orders vs /v2/orders) group separately in APM dashboards. If you're rolling out a new version behind a flag, you can compare v1 vs v2 p95 directly to catch regressions before full cutover.

How do I monitor API latency from the consumer side?

Synthetic monitoring: a tool that hits your API on a schedule from multiple regions and records response times. Postman Monitors, Better Stack (API checks), and UptimeRobot all do this. Internal server-side APM tells you server-side performance; synthetic monitoring tells you consumer-observed performance including network.

Related

Flat pricing, whatever your traffic does

Every plan starts with a 14-day free trial. No credit card needed.

Hobby
$5 a month

One app for a side project. Issues and alerts, with a 14-day dashboard window.

Start my 14-day trial
TeamRecommended
$15 a month

Up to 3 apps and 5 people per team. Full history, the MCP server, data clearing and agent health.

Start my 14-day trial
Agency
$69 a month

Unlimited client apps and people, one overview of every app, and apps you can hand over.

Start my 14-day trial