Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › API latency

Make Your API Faster: 15 Proven Techniques to Cut Latency Safely

By Freedom251 Team · · 9 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reliable way to improve API performance is to measure the complete request, find its dominant bottleneck, and change one variable at a time. Start with p50, p95, and p99 latency, throughput, errors, saturation, payload size, cache behavior, and database timing. Then apply the technique that matches the evidence: reuse connections and negotiate HTTP/2 or HTTP/3 for transport overhead; send fewer, smaller representations; cache only data with clear freshness and security rules; shape database work to the endpoint; and validate every change with production-like load and a rollback plan.

1. Establish a baseline before changing code

An average latency number hides the requests that users experience as slow. Record p50 (the median), p95, and p99 latency for each important route, along with throughput, error rate, resource saturation, response and request sizes, cache hit rate, and database timing. Keep the measurement window and traffic mix consistent so that before-and-after comparisons are meaningful.

As an Amazon Associate I earn from qualifying purchases.

Trace every part of a request

Distributed traces should separate DNS lookup, TCP connection, TLS negotiation, connection queueing, application handling, downstream calls, database work, and response serialization. A high p99 with a short application span points toward connection setup, queueing, or a downstream dependency; a long database span requires a different fix from a large serialization span. Instrument the same boundaries after each change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Turn an observation into a testable hypothesis

  • Observation: p95 rises when the connection pool is exhausted.
  • Hypothesis: connection reuse or pool sizing is limiting throughput.
  • Change: enable keep-alive and adjust the pool within the client and server limits.
  • Success criteria: lower p95 and p99 without increased errors, saturation, or connection churn.

Profilers and application telemetry can expose expensive queries and hot code paths. Measure the impact of a high-performance approach before accepting additional implementation complexity; a technically faster path that is difficult to observe or roll back may be a poor production trade.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

2. Remove transport and connection overhead

Reuse HTTP/1.1 connections

For HTTP/1.1, use persistent connections (keep-alive) and a correctly sized client connection pool. A new TCP and TLS handshake for every request adds latency and consumes sockets and CPU. Most HTTP libraries manage pools, but verify that the client is not creating a new client instance per call, that idle connections are retained for the expected period, and that pool limits are compatible with the server and load balancer.

  • Use one long-lived HTTP client per service or process rather than constructing clients inside request handlers.
  • Set maximum idle and total connections for the actual concurrency, then watch queue time and open-socket counts.
  • Confirm that proxies and load balancers do not close idle connections sooner than the client expects.

Negotiate HTTP/2 or HTTP/3 when the stack supports it

HTTP/2 and HTTP/3 multiplex multiple requests over a connection. This can reduce connection setup and head-of-line blocking compared with opening many HTTP/1.1 connections. Google Cloud generally recommends HTTP/3 or HTTP/2 for better performance, reduced head-of-line blocking, and greater resilience to network failures.

Protocol choice Potential benefit Checks before rollout
HTTP/1.1 with keep-alive Connection reuse with broad compatibility Pool size, idle timeouts, socket and queue metrics
HTTP/2 Multiplexing over one connection and fewer connection-level delays Client library, reverse proxy, load balancer, and tracing support
HTTP/3 Multiplexing over QUIC and improved behavior on some lossy networks QUIC/UDP support, proxy path, client fallback, and observability

Do not assume that an advertised protocol is the one being used. Inspect negotiated protocol telemetry at the edge and in representative clients. Preserve a tested fallback when an intermediary cannot support the newer protocol.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Compress text responses

Enable gzip or another encoding supported by your clients for JSON, XML, CSV, and similar text. Compression reduces bytes on the wire, but it consumes CPU and can add latency for tiny responses. Clients should advertise support with Accept-Encoding: gzip; verify that the response includes the corresponding Content-Encoding and that intermediaries preserve it.

  • Compress larger text responses where bandwidth or transfer time dominates.
  • Skip compression for already-compressed media and for very small bodies where framing costs exceed the saving.
  • Measure compression CPU, response size, and p95/p99 together; a lower payload size is not a win if server saturation increases.

3. Send less data and make request shapes bounded

Return only fields the client needs

Provide field selection or sparse fieldsets for representations that contain more data than every consumer uses. Omitting unused fields reduces transfer, parsing, and client storage work. Treat the field-selection syntax as part of the API contract: document allowed fields, preserve authorization checks for both selected and omitted data, and return a clear validation error for unknown or forbidden fields.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Keep a safe default representation for clients that do not select fields. Avoid allowing arbitrary database columns to become selectable; map public field names to an explicit allow-list so internal or sensitive attributes cannot be exposed accidentally.

Use PATCH for partial updates

When an update changes only a subset of attributes, PATCH can send just those changes instead of a complete resource. Define whether a missing field means “leave unchanged,” “clear,” or “use a default,” and state whether the operation is merge-style or replacement-style. Validate the resulting resource, not only the submitted fragment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For concurrent edits, document the conflict rule and use a version or validator when appropriate. A smaller request is useful only when clients and servers agree on merge, authorization, validation, and error semantics.

Paginate every collection

A collection endpoint must not return an unbounded result set. Large single responses increase database work, serialization time, network traffic, memory use, and tail latency. Require a bounded page size, enforce a server maximum, and return explicit pagination metadata.

  • Use a stable sort order so items do not jump between pages.
  • Prefer a continuation token for changing datasets; encode the position needed to continue without exposing implementation details.
  • Validate client-supplied page sizes and reject or clamp values above the server limit.
  • Define how deletions and inserts between requests affect traversal.

Set request and response size limits

Constrain body size, page size, filter complexity, upload parts, and batch counts before expensive processing begins. Streaming endpoints should stop reading when an acceptable limit is exceeded and can return HTTP 413 Payload Too Large for an oversized request. Apply limits at the edge and in the application so a bypassed proxy cannot remove the protection.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Control What it bounds Failure behavior to document
Maximum request body Memory, parsing, and upload work Reject with a size error before business processing
Maximum page size Query, serialization, and response transfer Reject or clamp with the effective size visible
Maximum batch count Transaction and downstream fan-out Return per-item or whole-batch validation errors
Filter and sort limits Query-planning and execution cost Reject unsupported or excessively complex expressions

4. Cache deliberately and validate freshness

Choose the cache layer that matches the data

Useful layers include browser or client caches, a CDN or gateway, an application cache, and database caches. A multi-layer strategy can reduce origin work and network latency, and a distributed cache is appropriate when multiple application instances need shared data. Gateway response caching can also serve repeated responses without invoking the application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Layer Best fit Primary concern
Client or browser Public or user-safe representations that tolerate local reuse Stale or sensitive data remaining on a device
CDN or gateway Cacheable responses shared across callers or regions Correct cache keys, authorization variation, and purge behavior
Application/distributed Expensive computations or shared reference data Eviction, consistency, and failure when the cache is unavailable
Database Repeated reads supported by the database engine Memory pressure and invalidation after writes

Write freshness and invalidation rules first

Cache frequently accessed, rarely changing, or expensive-to-generate data. Do not cache a response merely because it is slow. For each cacheable resource, specify its lifetime, what event invalidates it, whether stale data is acceptable, how authorization affects the key, and whether encryption is required. Frequently changing data needs an explicit invalidation strategy. Client-side caches can expose sensitive responses to other users of the device, so sensitivity belongs in the decision.

  • Vary keys by every request attribute that changes the representation, such as locale, tenant, permissions, and selected fields.
  • Prevent private responses from entering a shared cache unless the cache is explicitly partitioned and protected.
  • Define behavior when the cache is down: fail open to the origin, serve stale data, or fail closed for sensitive resources.

Use validators for unchanged resources

Send an ETag and, where useful, Last-Modified for representations that can be compared over time. A client can send If-None-Match or If-Modified-Since; if the resource has not changed, return 304 Not Modified without retransmitting the body. Ensure validators reflect the representation variant, including selected fields or content encoding, and do not let a validator bypass authorization.

5. Reduce network round trips

Each round trip adds network latency and creates another opportunity for queueing, failure, and retry amplification. When the domain permits, combine related reads, embed a narrowly defined related resource, or expose a batch endpoint. Keep those mechanisms bounded: batch size, authorization, per-item validation, and timeout behavior must be explicit.

Choose between embedding and separate resources

  • Embed a small, stable related object when clients nearly always need it and the combined response remains bounded.
  • Use separate calls when the related data is large, rarely needed, independently authorized, or independently cacheable.
  • Use a batch operation when many identifiers are known in advance, with strict limits and predictable per-item errors.

Measure the total user-visible transaction, not just one endpoint. A faster endpoint that forces clients to make four additional calls may increase page latency overall.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Shape database work to the endpoint

Filter, aggregate, and project in the database

Push filtering, grouping, aggregation, and column selection into the database instead of loading broad rows into application memory. Select only columns needed for the response or update. Inspect query plans for the real predicates, joins, and ordering used by production traffic.

Add indexes that match those predicates and sort orders, but keep them workload-specific. Every index consumes storage and adds write and maintenance work. Recheck plan stability after data volume or distribution changes; an index that helps one endpoint can slow writes or another query.

Eliminate N+1 access patterns

An N+1 pattern loads a collection with one query and then issues one additional query per item. It can look acceptable with a small development dataset and collapse under production cardinality. Inspect generated SQL and trace database calls per request.

  • Batch related lookups with an IN query or a deliberate join.
  • Use a projection that retrieves exactly the fields needed for the response.
  • Load related data explicitly rather than relying on accidental lazy loading.
  • Use read-only, no-tracking queries where the ORM supports them and the endpoint does not modify entities.

Compare query count, rows read, database CPU, lock waits, and endpoint tail latency after the change. Do not trade an N+1 pattern for a single join that multiplies rows and memory without checking its plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

7. Roll out changes with evidence and a rollback path

Test production-like conditions

Load tests should use representative payload sizes, concurrency, cache-warm and cache-cold states, geographic paths, database cardinality, and dependency failures. A benchmark with tiny objects and an empty cache cannot validate pagination, compression, query plans, or cache behavior.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Compare the same metrics before and after

Use the same p50, p95, p99, throughput, error, saturation, payload, cache, and database measurements from the baseline. Look for regressions in tail latency even when the mean improves. Record protocol negotiation, compression CPU, connection queues, query counts, and cache misses when those are relevant to the change.

Canary risky changes

Release protocol upgrades, cache policy changes, new indexes, ORM query rewrites, and batch endpoints to a small traffic slice first. Define rollback thresholds before deployment: for example, an error-rate increase, a p99 regression, cache leakage signal, database saturation, or elevated timeout rate. Keep the previous behavior available until the canary is stable.

Use a bottleneck-led sequence

  1. Instrument the request and establish percentile and trace baselines.
  2. Fix connection setup or protocol negotiation if transport spans dominate.
  3. Reduce representation size and enforce bounds when transfer or serialization dominates.
  4. Add caching or validators only after freshness, sensitivity, and invalidation rules are written.
  5. Shape queries and remove N+1 work when database spans or query counts dominate.
  6. Load-test the complete path, canary the change, and retain a measured rollback trigger.

How to choose among competing optimizations

Evaluate each proposal against the bottleneck it addresses, its correctness and freshness risk, CPU and memory cost, implementation complexity, observability requirements, rollback difficulty, and whether its benefit appears at p95 or p99 rather than only in the mean.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Technique category Extra decision factors
HTTP/2 or HTTP/3 Proxy, load-balancer, client, fallback, and telemetry compatibility
Compression CPU consumed versus bandwidth and transfer time saved
Caching Invalidation, authorization variation, encryption, and sensitive-data exposure
Database indexes and query rewrites Write overhead, memory use, plan stability, and production cardinality
Batching or embedding Response bounds, authorization, partial failure, and client complexity

There is no universal percentage improvement for these techniques. The measurable gain depends on payloads, geography, protocol support, workload shape, cache state, and dependency behavior. Treat each optimization as a hypothesis, and keep the instrumentation that proves whether it helped.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

API latencyAPI performancecachingdatabase performanceHTTP/2HTTP/3Load testingREST API optimization

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.