frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: PgDog – scale Postgres without changing the app

https://pgdog.dev/
1•levkk•1h ago
Hey HN!

Lev and Justin here, authors of PgDog (https://github.com/pgdogdev/pgdog), a connection pooler, load balancer and database sharder for PostgreSQL. If you build apps with a lot of traffic, you know the first thing to break is the database. We are solving this with a network proxy that works without requiring application code changes or database migrations.

Our post from last year: https://news.ycombinator.com/item?id=44099187

The most important update: we are in production. Sharding is used a lot, with direct-to-shard queries (one shard per query) working pretty much all the time. Cross-shard (or multi-database) queries are still a work in progress, but we are making headway.

Aggregate functions like count(), min(), max(), avg(), stddev() and variance() are working, without refactoring the app. PgDog calculates the aggregate in-transit, while transparently rewriting queries to fetch any missing info. For example, multi-database average calculation requires a total count of rows to calculate the original sum. PgDog will add count() to the query, if it’s not there already, and remove it from the rows sent to the app.

Sorting and grouping works, including DISTINCT, if the columns(s) are referenced in the result. Over 10 data types are supported, like, timestamp(tz), all integers, varchar, etc.

Cross-shard writes, including schema changes (CREATE/DROP/ALTER), are now atomic and synchronized between all shards with two-phase commit. PgDog keeps track of the transaction state internally and will rollback the transaction if the first phase fails. You don’t need to monkeypatch your ORM to use this: PgDog will intercept the COMMIT statement and execute PREPARE TRANSACTION and COMMIT PREPARED instead.

Omnisharded tables, a.k.a replicated or mirrored (identical on all shards), support atomic reads and writes. That’s important because most databases can’t be completely sharded and will have some common data on all databases that has to be kept in-sync.

Multi-tuple inserts, e.g., INSERT INTO table_x VALUES ($1, $2), ($3, $4), are split by our query rewriter and distributed to their respective shards automatically. They are used by ORMs like Prisma, Sequelize, and others, so those now work without code changes too.

Sharding keys can be mutated. PgDog will intercept and rewrite the update statement into 3 queries, SELECT, INSERT, and DELETE, moving the row between shards. If you’re using Citus (for everyone else, Citus is a Postgres extension for sharding databases), this might be worth a look.

If you’re like us and prefer integers to UUIDs for your primary keys, we built a cross-shard unique sequence, directly inside PgDog. It uses the system clock (and a couple other inputs), can be called like a Postgres function, and will automatically inject values into queries, so ORMs like ActiveRecord will continue to work out of the box. It’s monotonically increasing, just like a real Postgres sequence, and can generate up to 4 million numbers per second with a range of 69.73 years, so no need to migrate to UUIDv7 just yet.

    INSERT INTO my_table (id, created_at) VALUES (pgdog.unique_id(), now());
Resharding is now built-in. We can move gigabytes of tables per second, by parallelizing logical replication streams across replicas. This is really cool! Last time we tried this at Instacart, it took over two weeks to move 10 TB between two machines. Now, we can do this in just a few hours, in big part thanks to the work of the core team that added support for logical replication slots to streaming replicas in Postgres 16.

Sharding hardly works without a good load balancer. PgDog can monitor replicas and move write traffic to a promoted primary during a failover. This works with managed Postgres, like RDS (incl. Aurora), Azure Pg, GCP Cloud SQL, etc., because it just polls each instance with “SELECT pg_is_in_recovery()”. Primary election is not supported yet, so if you’re self-hosting with Patroni, you should keep it around for now, but you don’t need to run HAProxy in front of the DBs anymore.

The load balancer is getting pretty smart and can handle edge cases like SELECT FOR UPDATE and CTEs with INSERT/UPDATE statements, but if you still prefer to handle your read/write separation in code, you can do that too with manual routing. This works by giving PgDog a hint at runtime: a connection parameter (-c pgdog.role=primary), SET statement, or a query comment. If you have multiple connection pools in your app, you can replace them with just one connection to PgDog instead. For multi-threaded Python/Ruby/Go apps, this helps by reducing memory usage, I/O and context switching overhead.

Speaking of connection pooling, PgDog can automatically rollback unfinished transactions and drain and re-sync partially sent queries, all in an effort to preserve connections to the database. If you’ve seen Postgres go to 100% CPU because of a connection storm caused by an application crash, this might be for you. Draining connections works by receiving and discarding rows from abandoned queries and sending the Sync message via the Postgres wire protocol, which clears the query context and returns the connection to a normal state.

PgDog is open source and welcomes contributions and feedback in any form. As always, all features are configurable and can be turned off/on, so should you choose to give it a try, you can do so at your own pace. Our docs (https://docs.pgdog.dev) should help too.

Thanks for reading and happy hacking!

Lev & Justin

1•darkmatternews•10s ago

Show HN: Live AI Design Benchmark

https://shuffle.dev/ai-design
1•kemyd•22s ago•0 comments

PayPal Attracts Takeover Interest After Stock Slump

https://www.bloomberg.com/news/articles/2026-02-23/paypal-attracts-takeover-interest-after-stock-...
1•mikece•47s ago•1 comments

ClawSecurity: CrowdStrike for OpenClaw Agents

https://twitter.com/yq_acc/status/2025977732048511379
1•jiayaoqijia•1m ago•1 comments

Stressful People in Your Life Could Be Adding Months to Your Biological Age

https://www.pnas.org/doi/10.1073/pnas.2515331123
1•m463•1m ago•0 comments

Code isn't what's slowing projects down

https://shiftmag.dev/code-isnt-slowing-your-project-down-communication-is-7889/
2•birdculture•2m ago•0 comments

Strix Is an Open-Source Claude Code Security

https://www.strix.ai/
1•bearsyankees•3m ago•0 comments

Show HN: Plyra-guard – intercepts AI agent tool calls before execution

https://github.com/plyraAI/plyra-guard
1•plyra•4m ago•0 comments

Learn Visual Studio Code (E-Book)

https://lazarpress.gumroad.com/l/learnvscode
1•LouisLazaris•4m ago•1 comments

Global Intelligence Crisis – Summary

https://toolong.co/s/dl2dyojl
1•a_void_sky•5m ago•0 comments

Let's Discuss Sandbox Isolation

https://www.shayon.dev/post/2026/52/lets-discuss-sandbox-isolation/
1•shayonj•5m ago•0 comments

Claude Code for MBAs (Part 1)

https://essilfie.substack.com/p/claude-code-for-mbas-part-1
1•lordleft•6m ago•0 comments

Meta found 19% of young teen Instagram users saw unwanted nude or sexual images

https://www.reuters.com/legal/litigation/meta-survey-found-19-young-teen-instagram-users-saw-unwa...
1•giuliomagnifico•7m ago•0 comments

Cripix Technology?

1•kellkell•7m ago•0 comments

Open-AutoGLM: Zhipu AI's Open-Source Framework for Phone Agents (23k Stars)

https://theagenttimes.com/articles/open-autoglm-23k-stars-the-phone-agent-framework-from-chinas-a...
1•Ross00781•7m ago•0 comments

Decided to fly to the US to buy some hard drives

https://old.reddit.com/r/DataHoarder/comments/1rb9ot4/decided_to_fly_to_the_us_to_buy_some_hard_d...
2•HelloUsername•7m ago•0 comments

Some silly Z3 scripts I wrote

https://www.hillelwayne.com/post/z3-examples/
1•azhenley•8m ago•0 comments

Cryptographic Reciprocity for Shared Reality in the Deepfake Era

https://aquariuos.com
1•AquariuOS•8m ago•1 comments

Show HN: Yet Another Firebase Alternative

https://linkedrecords.com/
1•WolfOliver•8m ago•0 comments

AI is destroying open source, and it's not even good yet [video]

https://www.youtube.com/watch?v=bZJ7A1QoUEI
1•delduca•9m ago•0 comments

Simon Wardley – From here to there and back again

https://www.youtube.com/watch?v=hEjjCI3kTM4
1•RebootStr•9m ago•0 comments

The first general computer action model

https://si.inc/posts/fdm1/
5•nee1r•9m ago•3 comments

Rozenite Zustand Devtools

https://github.com/IronTony/rozenite-zustand-devtools
1•IronTony•10m ago•1 comments

Museum of Plugs and Sockets

https://plugsocketmuseum.nl/index.html
2•ohjeez•10m ago•0 comments

What the Wealthy Want in Their Private Jets

https://www.wsj.com/style/design/what-the-wealthy-want-in-their-private-jets-46b94ea0
1•bookofjoe•10m ago•1 comments

Sell Everything for This 1997 McLaren F1 GTR That's Going to Auction

https://www.thedrive.com/news/sell-everything-and-then-some-for-this-1997-mclaren-f1-gtr-thats-go...
1•PaulHoule•11m ago•0 comments

Federal Gov Trafficking Pregnant Children to Texas So They Can't Get Abortions

https://www.throughline.news/p/the-trump-administration-is-trafficking
2•hn_acker•12m ago•1 comments

Show HN: What I've learned from shipping 25 mobile apps

https://newsletter.masilotti.com/p/what-ive-learned-from-shipping-25
1•joemasilotti•12m ago•0 comments

Why doesn't Anthropic use Claude to make a good Claude desktop app?

https://manualdousuario.net/en/claude-desktop-app-ai-electron/
1•rpgbr•13m ago•0 comments

Infosec Exchange Mastodon server downsizing due to Hetzner price increase

https://infosec.exchange/@jerry/116120025252406744
1•speckx•13m ago•0 comments