Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to Transform Your Android Experience With the Best ROMs of 2026

    10 iPhone Hacks & Tips to Try in 2026

    Unveiling the Top Dating Apps of 2026: Find Your Perfect Match Today

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Ashley St. Clair, the mother of one of Elon Musk’s children, sues xAI over Grok sexual images

      January 17, 2026

      Anthropic joins OpenAI’s push into health care with new Claude tools

      January 12, 2026

      The mother of one of Elon Musk’s children says his AI bot won’t stop creating sexualized images of her

      January 7, 2026

      A new pope, political shake-ups and celebs in space: The 2025-in-review news quiz

      December 31, 2025

      AI has become the norm for students. Teachers are playing catch-up.

      December 23, 2025
    • Business

      New VoidLink malware framework targets Linux cloud servers

      January 14, 2026

      Nvidia Rubin’s rack-scale encryption signals a turning point for enterprise AI security

      January 13, 2026

      How KPMG is redefining the future of SAP consulting on a global scale

      January 10, 2026

      Top 10 cloud computing stories of 2025

      December 22, 2025

      Saudia Arabia’s STC commits to five-year network upgrade programme with Ericsson

      December 18, 2025
    • Crypto

      Trump Shifts on Fed Pick as Hassett Odds Fade: Who Will Replace Powell?

      January 17, 2026

      A Third of French Crypto Firms Still Unlicensed Under MiCA as Deadline Nears

      January 17, 2026

      DOJ Charges Venezuelan National in $1 Billion Crypto Laundering Scheme

      January 17, 2026

      One of Wall Street’s Top Strategists No Longer Trusts Bitcoin | US Crypto News

      January 17, 2026

      3 Altcoins To Watch This Weekend | January 17 – 18

      January 17, 2026
    • Technology

      How to Transform Your Android Experience With the Best ROMs of 2026

      January 18, 2026

      10 iPhone Hacks & Tips to Try in 2026

      January 18, 2026

      Unveiling the Top Dating Apps of 2026: Find Your Perfect Match Today

      January 18, 2026

      What Is the Newest Samsung Galaxy Phone? (2026)

      January 18, 2026

      Master Speed Reading With These Top Apps for iOS and Android in 2026

      January 18, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»You Can Make Postgres Scale
    Technology

    You Can Make Postgres Scale

    TechAiVerseBy TechAiVerseMarch 14, 2025No Comments7 Mins Read2 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    You Can Make Postgres Scale
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    You Can Make Postgres Scale

    Mar 13th, 2025
    Lev Kokotov

    Postgres scales. No other two words that I’ve ever heard of, produced more controversy. At least in the circles I hang out in, in the company basement where infrastructure elves make the Rails app go brrr.
    A lot of people believe, against all odds, and marketing campaigns by Big NoSQL, that technology you know is better than the devil you just heard pitched at the Engineering Leadership meeting.

    To be completely fair, I get where they are coming from. Making Postgres write more data can be challenging. You need more hardware. Most of the time, you can just get it by pushing the “Upgrade” button. Once you’ve reached the r5.24xlarge instance, with 5 replicas, just as substantial, and your vacuums are still behind schedule, things are getting pretty scary.

    This is where the test of a true engineer begins. At the edge. To be clear, I’m not talking about WebAssembly. I’m talking about that engineering spirit that looks at a problem, while under executive fire, and instead of running into the hands of your nearest sales team with big promises (but little facts about your use case), solves it using first principles.

    And a first principle tells us what we need. Postgres ran out of write capacity. Either because of lock contention on the WAL, or something got the vacuum stuck. It’s probably that idle transaction that’s been open for 45 seconds while the app is making a Stripe call, but that’s not our concern. We’re the infrastructure team, and our job is to make the DB work.

    So we decided, collectively as a community of duct tape enthusiasts, that we will give Postgres what it wants: more machines. We are going to split that write workload, evenly between 3 (no, let’s go with 6, just to be safe) databases. If the theory of “more is better” is correct, then we should get 6 times more writes.

    The road taken

    It’s funny to write this. The Internet contains at least 1 (or maybe 2) meaty blog posts about how this is done. Funny, because they describe a lot of work that was done by a team of about 5. That team went through every single ActiveRecord and psycopg2 execute call to make sure it contains a sharding key.

    We took a failing database, while it was serving about 100,000 users per second, ran dozens of scary looking (and mostly undocumented) commands to get it to keep that replication slot open while we snapshot it, restore it 6 different ways, and truncate most of the data to get it in sync with the new sharding scheme.

    We synchronized it with logical replication, which took a day or two. These databases are precious and one accidental write can break data integrity. So the team added triggers that validate rows that are going into every table. We picked a hashing function Postgres came with since version 10, which we found in the bowels of the mailing lists. It’s a function we can call to validate rows manually or reshard data.

    Data is sharded, but we didn’t tell the application how to find it. It was in 1 database, now it’s in 6. Luckily, Postgres is open source. We found the code for that hashing function, rewrote it in Ruby, and plugged it into the ApplicationRecord class. Every time someone executes a query, that code will hash the sharding key and send the query to one of the instances configured in database.yml. If it’s a SELECT, it’ll get special treatment and will be load-balanced against 5 replicas.

    Python got the short end of the stick and used a special coordinator we created using partitioned foreign tables. That will also serve 1% of cross-shard queries we couldn’t untangle in time. Postgres is scary and versatile sometimes.

    The team created 5 replicas for each shard. We were not kidding around this time. We never want to do this manual process again. This should keep them going for another…years. We don’t know how many because we have never seen growth like this before, but we can always add more replicas. Adding more shards though is a problem for another time. We know we can, because we got this far, and our engineering spirit is strong, but we just want to get this done.

    If you’re counting with me, we’re at 36 databases. Plenty of room to grow 6x again.

    Time came to write that Pgbouncer config. Too bad it can’t load balance traffic for us, but that’s okay. We have an ActiveRecord plugin that will figure it out, and the Python apps can just use replica-5-prod. It’s 10:45pm, 2 hours before the maintenance window we negotiated with the business folks, who still don’t understand why we need to take the whole app offline for a few hours every other week.

    The cutover plan is simple. Shut down the database and switch the app to the new ones. Easy enough.

    The time has come. The familiar concerto of Datadog, Rollbar and CloudWatch alarms starts playing. PagerDuty is ringing. Nobody is getting woken up though, we’re all here already. We forgot to set that maintenance window, but there is no time now. The business is offline and we have about 5 minutes to switch configs, manually test that everything is working, and turn the traffic back on.

    Somebody wrote a Bash script to reload all the bouncers at once. Good for that person, that’s good thinking. Infrastructure engineers use Bash for everything. First principles.

    The app is ready, we ran a few queries and sanity checks to make sure everything is good to go. We’re about to flip the switch back on when one of the engineers quietly asks (it’s 2 in the morning, after all):

    “Hey guys, did we bump up the sequences?”

    Crap. Logical replication doesn’t handle that little detail, but that’s ok, we still have that PL/pgSQL script from the last time we did this. Quick copy/paste job into the superuser psql session and we’re back in business, with plenty of room to grow the company, and a hell of a story.

    The case for Postgres

    Okay, that was perhaps not the cheeriest sales pitch. For the skeptic, this really could go either way, and maybe DynamoDB is the better choice for their next greenfield project. If you’re still reading this though, you just saw a roadmap for how Postgres can be sharded. It’s not only possible, it’s actually quite doable, and it’s been done.

    What we really need now is a piece of code that does it for us. Preferably automatically, in the background, while we’re busy writing more ActiveRecord queries to sell stuff. Out of this belief, and because scaling Postgres should be done after lunch with a push of a button, we wrote PgDog.

    For you, and because we can. It is, we believe, the answer to “Does Postgres scale?”. Yes it does. It did and it will, for as long as we, the engineers, make it so.

    Get in touch

    If any of this rings familiar, or you’re just curious about the project, get in touch. PgDog is an open source project for sharding Postgres.

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticlePrequel (YC W21) Is Hiring a Strong Front End Engineer
    Next Article The Curious Surge of Productivity in U.S. Restaurants
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    How to Transform Your Android Experience With the Best ROMs of 2026

    January 18, 2026

    10 iPhone Hacks & Tips to Try in 2026

    January 18, 2026

    Unveiling the Top Dating Apps of 2026: Find Your Perfect Match Today

    January 18, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025619 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025235 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025135 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025109 Views
    Don't Miss
    Technology January 18, 2026

    How to Transform Your Android Experience With the Best ROMs of 2026

    How to Transform Your Android Experience With the Best ROMs of 2026 A custom ROM…

    10 iPhone Hacks & Tips to Try in 2026

    Unveiling the Top Dating Apps of 2026: Find Your Perfect Match Today

    What Is the Newest Samsung Galaxy Phone? (2026)

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    How to Transform Your Android Experience With the Best ROMs of 2026

    January 18, 20260 Views

    10 iPhone Hacks & Tips to Try in 2026

    January 18, 20260 Views

    Unveiling the Top Dating Apps of 2026: Find Your Perfect Match Today

    January 18, 20260 Views
    Most Popular

    A Team of Female Founders Is Launching Cloud Security Tech That Could Overhaul AI Protection

    March 12, 20250 Views

    Senua’s Saga: Hellblade 2 leads BAFTA Game Awards 2025 nominations

    March 12, 20250 Views

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.