---
title: "How to Minimise the Impact of Database Latency"
description: "Database round-trip latency compounds with every sequential query, so co-locating the backend with the database and cutting round trips matters more than raw query speed."
url: "https://swe.quest/articles/how-to-minimise-the-impact-of-database-latency-bc4c9682c5942467"
canonical: "https://neon.com/blog/how-to-minimise-the-impact-of-database-latency"
source: "Neon"
published: "2024-06-07"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["postgres","performance","sql","serverless"]
---

# How to Minimise the Impact of Database Latency

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-06-07, 9 min read, How-to. Original: [https://neon.com/blog/how-to-minimise-the-impact-of-database-latency](https://neon.com/blog/how-to-minimise-the-impact-of-database-latency)

## Summary

Database round-trip latency compounds with every sequential query, so co-locating the backend with the database and cutting round trips matters more than raw query speed. Neon's open-source Regional Latency Dashboard gives P50/P99 latencies between hosting providers and Neon regions, which can be multiplied by query count to estimate N+1 costs. The fixes are JOINs or bounded IN queries instead of N+1 loops, Django's select\_related/prefetch\_related, batching queries in one transaction (45% faster in a simple benchmark), Postgres RETURNING and ON CONFLICT clauses, connection reuse (8-9x lower response times in a Django sample), and application-level connection pools (10x+ throughput).

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)

## Prerequisites

- SQL joins ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- ORM usage

## Keywords

Neon, Regional Latency Dashboard, N+1 problem, Django, Drizzle ORM, @neondatabase/serverless, node-postgres

## Related posts

- [Sub-10ms Postgres queries for Vercel Edge Functions](https://swe.quest/articles/sub-10ms-postgres-queries-for-vercel-edge-functions-6bc9caef6fab65ca.md): Neon · 2023-07-10 · Medium · 3 min read · PostgreSQL, Serverless, CDN & edge, Performance engineering, TypeScript
  Neon's serverless Postgres driver now supports SQL-over-HTTP via fetch, and Neon's proxy adds opt-in experimental connection caching (\`fetchConnectionCache\`).
- [How to Handle Database Connection Pooling](https://swe.quest/articles/how-to-handle-database-connection-pooling-1d65f2947c3645f4.md): Railway · 2024-12-13 · Medium · 13 min read · PostgreSQL, JavaScript, Performance engineering, Databases
  Connection pooling keeps a set of reusable database connections open, so requests check one out and return it instead of opening and closing a connection per query.
- [HTTP vs. WebSockets: Which protocol for your Postgres queries at the Edge](https://swe.quest/articles/http-vs-websockets-which-protocol-for-your-postgres-queries-at-the-edge-25a9317092665f21.md): Neon · 2023-07-11 · Medium · 5 min read · PostgreSQL, Serverless, Performance engineering, CDN & edge, Networking
  Neon's serverless Postgres driver now supports SQL-over-HTTP alongside WebSockets, and benchmarks from Vercel Edge and Serverless functions (iad1 to us-east-1) show each wins in different cases.
- [Using Neon’s Scale to Zero with Long-Running Applications](https://swe.quest/articles/using-neon-s-scale-to-zero-with-long-running-applications-bbe64dd8466d86d8.md): Neon · 2024-01-24 · Medium · 7 min read · PostgreSQL, Serverless, Resilience, JavaScript, Performance engineering
  Neon's scale to zero suspends a Postgres compute after an idle window (only when no WAL senders are active and autovacuum isn't running), which severs connections held by long-running servers.
- [Quicker serverless Postgres connections](https://swe.quest/articles/quicker-serverless-postgres-connections-7a37a1071edd4362.md): Neon · 2023-03-28 · Medium · 8 min read · PostgreSQL, Networking, Serverless, Performance engineering, Cryptography
  Neon cut the network round-trips needed to get a first query result from its WebSocket-based serverless Postgres driver from nine to four.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
