DEV Community

Cover image for Your Vibe coded Dating App Went Viral. Can Your Database Handle It?
Saurabh "Rob" Dahal
Saurabh "Rob" Dahal

Posted on

Your Vibe coded Dating App Went Viral. Can Your Database Handle It?

You’re tired of the same old dating apps, so you spend a weekend vibe-coding your own. You call it MainSqueeze. The idea? Give somebody in New York City a better shot at finding the love of their life. You run the app and its PostgreSQL database on your laptop and send a few single friends the link.

ne of ten phones shows Rob’s MainSqueeze profile. He taps Create profile to send his signup to your laptop. The app checks his form and PostgreSQL saves row R12, Rob, Astoria, Coffee dates. Lucie’s existing row, L34, appears above his. The laptop replies “Profile ready” to Rob’s phone.

Each friend has their own screen. All ten profiles live in the same table on your laptop.

It works. Matter of fact, this funny-looking dude matches with a hot Slavic chick he had no business matching with. Look at you, working miracles already!

(Okay, side note: that dude on the cover is me, Rob. And that’s my wife, Lucie. I met her by walking up to her in person while she was sitting on a park bench. Yes, the author of this blog has a mouthpiece and rizz, no dating app needed LOL. For the sake of this blog, let’s pretend it happened in your vibe-coded dating app.)

Then somebody shares our match with a link. “Wait. If that guy matched with her, I’m signing up.” First it’s ten people trying to sign up in a minute. Then a hundred. Then, dare I say it…

Dr. Evil raises his pinky. The caption reads “1 MILLION USERS”.

A million people trying to sign up in one minute. Then the messages start. “Hey, I tapped Create profile. Is it supposed to keep spinning?” Then, “All the Slavic cuties will be gone by the time I set up my profile!”

Why traffic spikes cause database timeouts

Compare what happens to the same signup as the crowd grows. Your backend, the app code running on your laptop, checks the form. PostgreSQL adds the profile to its Profiles table. Adding data is a write. Once PostgreSQL finishes, the backend sends "Profile ready" to the phone.

At ten signups a minute, your laptop keeps up. At a hundred, people who joined earlier open Discover, the screen that finds nearby dates. Ten people search for coffee dates in Astoria, so the backend asks PostgreSQL the same question ten times. Looking up data is a read. Those reads now compete with new profile writes for the laptop's processor, memory and disk.

Now imagine my signup arriving during the million-signup minute. One million divided across 60 seconds averages about 16,700 forms per second. That does not mean PostgreSQL fails at 16,700 requests per second. This is an illustration, not a benchmark. Form size, database queries, connections and hardware all affect the limit.

If requests arrive faster than the laptop can finish them, they wait in a queue. My profile write waits behind the other reads and writes. The phone stops waiting before PostgreSQL replies, so it shows a timeout. Apparently even databases can leave you on read.

As signup attempts rise from 10 to 100 to one million per minute, Discover reads join profile writes on the same laptop. More requests pile up than it can finish, and Rob’s phone waits for confirmation.

The traffic counts are illustrative. A load test, which sends controlled test traffic, shows where your app slows down.

Why retries can create duplicate database writes

I get in, spot Lucie and tap Like. My phone waits for the backend, then times out. It offers Try again, so I tap it. You put the button there. I am merely following orders.

PostgreSQL may have saved "Rob likes Lucie" before the confirmation got stuck in the queue. A timeout tells the phone that it did not receive an answer. It does not prove that the database write failed.

My second tap sends the same request. If the backend inserts another row, Lucie sees my face twice. I was aiming for interested, not "standing outside with a boombox."

Rob’s Discover screen shows Lucie. The laptop saves one like from R12 (Rob) to L34 (Lucie). Rob’s phone times out. Try again sends the same two IDs.

The backend needs a safe way to recognize the same like twice. We will add that rule after moving the app.

How to scale an app with Elastic Beanstalk and Amazon RDS

You would like to close your laptop. New York would like to keep dating. AWS lets you run the backend and database on remote computers in its data centers instead of on your kitchen table.

For this example, AWS Elastic Beanstalk Standard Mode runs the backend on Amazon EC2 app servers. A load balancer spreads incoming requests across healthy copies of the backend. Rob's form can go to one copy while Lucie's goes to another.

Auto Scaling can add app servers when a metric such as request count or processor use crosses a limit that you configure. New servers need time to start, so Auto Scaling cannot rescue an unprepared app the instant Dr. Evil raises his pinky. Set minimum and maximum server counts, choose useful scaling triggers, and test them. How Elastic Beanstalk distributes requests · How Elastic Beanstalk Auto Scaling works

Amazon Relational Database Service (RDS) for PostgreSQL runs the same PostgreSQL database engine on separate AWS resources. Your tables and SQL queries can move with the database, though extensions and version compatibility still need checking. Every backend copy connects to the same primary database, so adding app servers does not add database write capacity.

Watch the database's processor use, connections, read and write latency, and disk queue. Fix slow queries and missing indexes first. If the database still lacks processor or memory, move to a larger DB instance class. If storage cannot finish reads and writes fast enough, increase its IOPS or throughput. Changing an RDS instance class causes an outage, so plan that change instead of treating it like a turbo button during the rush. RDS for PostgreSQL · RDS DB instance classes · RDS storage performance

Rob and Lucie submit profiles. A load balancer sends their forms to separate copies of MainSqueeze. Both copies write to the same Profiles table in RDS, then the phones get confirmation.

This design separates the backend from PostgreSQL and lets you scale each one. It does not guarantee one million successful signups per minute. Only a load test against your configuration can show that.

How Amazon ElastiCache reduces PostgreSQL database load

More app servers help the backend check forms, but all of them still share RDS. Repeated Discover searches consume database capacity that new profile writes could use. A cache can remove some of those repeated reads.

Lucie and I open Discover one second apart. Both phones need candidates for Astoria + coffee. The backend first asks Amazon ElastiCache, a managed in-memory cache that can return saved results faster than a database query.

My request finds no saved list. That is a cache miss. The backend searches the Profiles table in RDS, receives candidate IDs such as R12 and L34, and stores that list in ElastiCache for 30 seconds. ElastiCache is a temporary copy. RDS remains the source of truth.

Lucie's request finds the list. That is a cache hit, so the backend skips the repeated neighborhood search. It removes Lucie's own ID, because matching with yourself creates paperwork, and checks current visibility, preferences and blocks before showing profiles. Those safety checks may require more reads, but RDS performs one neighborhood search instead of two.

Thirty seconds is an example expiration time, not a recommendation for every app. A short expiration returns new profiles sooner but sends more searches to RDS. A long expiration saves more reads but can show older candidates. ElastiCache may also evict an entry when it needs memory. The next request then reads fresh data from RDS. How cache-aside, expiration and eviction work

Rob opens Discover and sees Lucie after the AWS backend misses in ElastiCache, searches RDS for Astoria coffee dates and caches the candidate IDs. Lucie opens a second later, gets a cache hit and sees Rob after her own checks.

Start with a sound query and the right PostgreSQL index. Add a cache after measurements show that repeated reads are worth the extra service and stale-data rules.

When to use Amazon DynamoDB for high-traffic user lookups

Discover asks, "Who is nearby?" The Likes inbox asks, "Who liked me?" Start with a Likes table in PostgreSQL on RDS. Add an index to the recipient_id column. Like the index at the back of a book, it helps PostgreSQL find Lucie's rows without reading the whole table. If the inbox stays fast and signups keep up, keep this simpler design. How PostgreSQL indexes work

Suppose a load test shows that inbox traffic still slows profile signups. You decide to move the Likes data and its new writes to Amazon DynamoDB, while Profiles remain in RDS. That move requires a data migration and backend changes. AWS does not sneak into PostgreSQL at night and relocate the rows while you sleep.

DynamoDB is a managed NoSQL database. AWS handles its servers and divides a table's data across storage partitions. You design the table around the questions the app must answer instead of joining relational tables with SQL.

For MainSqueeze, every inbox query starts with a recipient ID. Store each like with:

  • Partition key: the recipient ID, such as L34, which groups Lucie's likes.
  • Sort key: the sender ID, such as R12, which makes each sender-recipient pair unique inside her group.

Lucie opens Likes, and the backend queries partition key L34. DynamoDB returns the items with senders R12 and U08. The backend turns those IDs into Rob and Member 08 on her screen. Member 08's like for Rob uses recipient R12, so it appears in Rob's inbox instead.

This key design answers "Who liked Lucie?" It does not answer "Whom did Lucie like?" without another access path, such as a global secondary index, or a different item design. DynamoDB works best when you list these questions before choosing the keys. How DynamoDB partition and sort keys work · How DynamoDB queries a partition key

In on-demand capacity mode, DynamoDB adjusts table capacity as traffic changes. A sudden jump beyond the table's prepared throughput can still cause throttling, which means DynamoDB temporarily rejects requests. Test the surge and raise warm throughput before a planned launch if needed. Different recipient IDs spread activity, but one celebrity inbox can become a hot key. Apparently databases also have to deal with influencers. DynamoDB on-demand scaling and warm throughput · DynamoDB partition-key design

Querying recipient L34 returns two likes for Lucie, from R12 (Rob) and U08 (Member 08). A third like goes from U08 to R12. It appears when Rob opens his inbox.

Use DynamoDB because a measured access pattern fits its key model, not because traffic grew and somebody yelled "NoSQL."

How to prevent duplicate writes in PostgreSQL and DynamoDB

Now return to my second tap. In PostgreSQL, a UNIQUE (sender_id, recipient_id) constraint can reject a second row for the same pair. The backend handles that conflict and returns Like sent instead of creating a duplicate.

In DynamoDB, the recipient ID and sender ID form the item's complete primary key. The backend uses a conditional write that says, "Save this item only if an item with this key does not exist." If my first tap already created the item, DynamoDB rejects the second write. The backend recognizes that specific condition failure and returns Like sent. One man, one like. PostgreSQL and DynamoDB have both endorsed monogamy. PostgreSQL unique constraints · DynamoDB conditional writes

Lucie taps Like back. Her like uses sender L34 and recipient R12. After saving it, the backend reads the opposite item, sender R12 and recipient L34, from the DynamoDB base table.

DynamoDB reads are eventually consistent by default, so a read can briefly return an older result after a write. The match check requests a strongly consistent read to get the latest completed write. Strong reads consume twice the read capacity of eventually consistent reads and do not work on global secondary indexes, so use them only where fresh data affects the result. The backend finds both likes and shows the match. How DynamoDB read consistency works

Rob’s retry leaves one like from Rob to Lucie. Lucie likes Rob back, reversing the sender and recipient IDs. The match screen shows their beach photo and says “It’s a match!”

One like in each direction. Now somebody has to pick a coffee shop, which may be the hardest distributed-systems problem in this article.

Friday night, New Yorkers are still matching while your laptop is closed. That funny-looking dude from the cover is married to Lucie. You can take credit for our match in this story. The park bench knows the truth.

Rob and Lucie smile together with the Empire State Building lit up behind them.

In PostgreSQL, COMMIT makes a transaction's changes stick. She said "I do." I said "I do." PostgreSQL heard COMMIT.

How to try this AWS architecture with the AWS Free Tier

You can test pieces of this architecture with the new AWS Free account. New customers receive $100 in AWS credits at signup and can earn up to another $100 by completing activities in the AWS console. The Free plan lasts until the credits run out or six months pass, whichever happens first. AWS does not charge you unless you upgrade to the Paid plan. Check the current Free plan terms and supported-service list before you build.

The services from this article can fit into that learning account, but they do not all have the same free allowance:

  • Elastic Beanstalk Standard Mode has no platform fee. Its EC2 instance, EBS volume, public IPv4 address and optional load balancer consume credits. Cluster Mode is not Free Tier eligible. Review Elastic Beanstalk Free Tier pricing.
  • Amazon RDS for PostgreSQL is available on the Free plan. For accounts created after July 15, 2025, database instance, storage and backup usage draw from your credit balance. Review Amazon RDS pricing.
  • Amazon ElastiCache is available on the Free plan, including serverless and node-based options. Its usage draws from your credits. Review Amazon ElastiCache pricing.
  • Amazon DynamoDB has an always-free monthly allowance for Standard tables using provisioned capacity, including 25 GB of storage, 25 read capacity units and 25 write capacity units. The on-demand mode used in this article draws from your credits instead. Review DynamoDB Free Tier limits.

Start with one small service at a time. Confirm your selected Region in AWS Settings > View all projects > Overview > Additional Info > Region, because your project creates Regional resources there. Watch your credit balance in AWS Settings > Billing, and delete the RDS database, ElastiCache cache and Elastic Beanstalk environment when you finish. Nothing ruins a dating-app success story like getting ghosted by your own cleanup checklist.

Top comments (0)