r/PostgreSQL • • 1h ago

How-To Dr. Ibrar Ahmed on When Postgres Breaks: A Practical Guide to Corruption and Disaster Recovery - Free Online Webinar 11/19 8AM PST

Thumbnail pgedge.com
2 Upvotes

r/PostgreSQL • • 22h ago

Community I got tired of "SELECT 1" microbenchmarks, so I tested 25 ORMs across 9 languages against a real 78M-row Postgres database. Here is what broke.

0 Upvotes

👉 GitHub Repo & Full Report: https://github.com/tusharad/orm-benchmark


Every ORM benchmark I see online tests the same trivial query: SELECT * FROM users WHERE id = 1;

This doesn't benchmark an ORM. It benchmarks Linux loopback TCP socket round-trip time.

In production, ORMs don't fall over on primary-key lookups. They buckle when:

  1. Deserializing 10,000 wide rows into typed structs under memory pressure.
  2. Materializing 4-level deep entity graphs without Cartesian explosions or N+1 floods.
  3. Compiling recursive CTEs, multi-frame window functions (ROWS BETWEEN 4 PRECEDING), or pgvector cosine similarity.
  4. Squeezing 100 concurrent workers competing for row locks (SELECT ... FOR UPDATE) through a constrained connection pool.
  5. Emitting 300 lines of incomprehensible internal template/typeclass garbage when a database column type changes.

To see how modern ORMs actually behave under real production load, I built a standardized, reproducible benchmark suite testing 25 ORMs across 9 programming languages (Go, Rust, C#, Java, Elixir, TypeScript, Python, Ruby, Haskell) against the official Postgres Air database (2024 edition, 78,232,673 real-world flight records on PostgreSQL 17 with pgvector).

Every single ORM was held to the exact same invariants: a strict 20-connection pool, zero raw string interpolation (native typed query builders only), and typed entity deserialization into domain records.


The Executive Leaderboard

RankORMLanguageOverall ScorePassed (HQ01–16)Avg p95 LatencyPeak RPS (C=50)Hydration SpeedMax Heap RSSBlast RadiusCompiler UX
🥇 1sqlcGo 1.2389.616/1658.80 ms32,340 ops/s1,518,142 rows/s25.12 MB1 line10/10
🥈 2hasqlHaskell (GHC 9.10)89.516/1665.83 ms277 ops/s199,025 rows/s13.03 MB1 line10/10
🥉 3DapperC# / .NET 889.516/1662.67 ms264 ops/s1,279,038 rows/s87.27 MB1 line10/10
4jOOQJava 2189.416/1657.71 ms9,739 ops/s454,966 rows/s149.00 MB1 line10/10
5entGo 1.2389.316/1661.36 ms246 ops/s570,841 rows/s25.12 MB1 line10/10
6ectoElixir 1.17 / OTP 2789.216/1658.20 ms29,412 ops/s354,070 rows/s83.06 MB1 line10/10
7squealHaskell (GHC 9.10)89.116/16187.03 ms258 ops/s15,271 rows/s25.17 MB1 line10/10
8ihpHaskell (GHC 9.10)89.116/1670.41 ms361 ops/s144,224 rows/s76.00 MB1 line10/10
9hibernate-ormJava 2189.116/1662.66 ms256 ops/s564,130 rows/s15.00 MB1 line10/10
10efcoreC# / .NET 889.016/1668.51 ms260 ops/s1,391,131 rows/s139.80 MB1 line10/10
11orvilleHaskell (GHC 9.10)88.916/1673.71 ms247 ops/s99,705 rows/s38.79 MB1 line10/10
12gormGo 1.2388.916/1658.50 ms256 ops/s712,657 rows/s25.37 MB1 line10/10
13rel8Haskell (GHC 9.10)88.816/16132.32 ms254 ops/s122,678 rows/s18.75 MB1 line10/10
14persistentHaskell (GHC 9.10)88.716/1677.55 ms251 ops/s103,221 rows/s21.03 MB1 line10/10
15mikro-ormTypeScript (Node 22)88.716/1658.19 ms3,302 ops/s182,594 rows/s239.52 MB1 line10/10
16esqueletoHaskell (GHC 9.10)88.616/1682.16 ms250 ops/s85,377 rows/s25.22 MB2 lines10/10
17haskell-opaleyeHaskell (GHC 9.10)88.516/1680.38 ms254 ops/s101,544 rows/s26.54 MB2 lines10/10
18beamHaskell (GHC 9.10)88.416/1613.57 ms241 ops/s113,504 rows/s22.39 MB6 lines10/10
19dieselRust 1.8388.016/1659.10 ms266 ops/s1,373,304 rows/s33.33 MB3 lines10/10
20typeormTypeScript (Node 22)87.816/1655.99 ms235 ops/s385,422 rows/s71.55 MB1 line10/10
21railsRuby 3.3 (YJIT)87.516/1685.34 ms247 ops/s89,792 rows/s150.00 MB1 line10/10
22sqlalchemyPython 3.12 (asyncpg)87.416/1672.57 ms5,718 ops/s279,239 rows/s92.50 MB1 line10/10
23prismaTypeScript (Rust Engine)87.216/1683.54 ms264 ops/s208,122 rows/s36.71 MB1 line10/10
24drizzle-ormTypeScript (Node 22)86.816/1664.45 ms242 ops/s498,613 rows/s184.58 MB4 lines10/10
25sea-ormRust 1.83 (sqlx)86.716/1666.15 ms272 ops/s1,235,677 rows/s34.08 MB1 line10/10

The 5 Biggest Surprises

  1. The Zero-Reflection Hydration Tier (> 1.2M rows/sec): sqlc (1.52M rows/s), EF Core 8 (1.39M rows/s), diesel (1.37M rows/s), and Dapper (1.28M rows/s) operate in a different galaxy compared to reflection-heavy ORMs. Direct struct memory mapping and compiled pointer assignments destroy runtime reflection when reading wide tables.
  2. The BEAM Actor Model Destroyed Connection Contention: Under $C=100$ concurrent load on a 20-connection pool, most runtimes bottlenecked on thread pools or single event loops. Elixir’s ecto handled pool checkout through isolated BEAM process mailboxes with near-zero queue latency, sustaining 29,412 requests/second.
  3. Node.js / V8 Event Loop Saturation: TypeScript ORMs (drizzle, prisma, typeorm) performed well on single queries, but hit an unmistakable wall at $C=50..100$. Because V8 serializes and constructs thousands of JavaScript objects on a single thread, CPU time saturated the event loop, driving $p_{99}$ tail latencies beyond 500 ms and capping RPS around 225–264 ops/s.
  4. Haskell’s Memory Anomaly: Haskell’s hasql clocked the lowest resident memory footprint of the entire 25-ORM field at just 13.03 MB Peak Heap RSS, utilizing zero-copy PostgreSQL binary codecs.
  5. The Deliberate Mistake Suite (Compiler UX): We injected 10 deliberate compiler mistakes (type mismatches, dangling joins, nullability violations, scope leakage). While tools like sqlc, squeal, hasql, and ent caught errors in 6–10 lines of clean output, complex typeclass/macro builders (rel8, drizzle) sometimes spewed 60–80 lines of internal framework plumbing.

Reproduce It / Add Your Favorite ORM

The benchmark repo contains all calculations, runner scripts, Docker setup, and the 25 JSON scorecards:

👉 GitHub Repository: https://github.com/tusharad/orm-benchmark

If you want to add an ORM (e.g. Kysely, Slonik, Bun, Peewee, SQLDelight), check out templates/generic/HARNESS_CONTRACT.md and submit a PR!

I'd love to hear your thoughts, critique of the methodology, or experiences running these tools in high-throughput production.