Back to the Lab

The Lab · database

Building a Global Leaderboard with Neon Postgres and Zero Infrastructure Cost

Serverless Postgres for side projects. One npm install, one env var, global leaderboard running for free.

RAXXO Studios 2 min read
TLDR This entry in one minute

Each line jumps to its section

Serverless databases changed how small projects ship. No connection pooling headaches. No idle server costs. Just a URL and a query.

Neon Postgres for Side Projects

Neon gives you a full Postgres database with a generous free tier. The serverless driver works in edge functions, Vercel Functions, and any serverless environment without the TCP connection overhead traditional Postgres clients need.

Setup in 60 Seconds

One npm install. One environment variable. One function call. Import neon from the serverless package, pass your POSTGRES_URL, and run tagged template queries. No pool configuration. No connection limits. No pgBouncer.

Schema Design for Leaderboards

A global leaderboard needs two things: an attempts table and a stats table.

The attempts table stores every submission with deviation, timestamp, region, and user agent. The stats table holds aggregate counters (total attempts, best ever, success count) updated atomically on each submission.

Ranking is a single query: count how many attempts have a lower deviation than yours. Your rank is that count plus one.

Rate Limiting Without Redis

For a side project, in-memory rate limiting works. A Map of IP addresses to last-submission timestamps. Check the gap before accepting. Clean up entries older than 10 seconds when the map grows past 10,000 entries.

Not production-grade for high traffic. Perfect for a game that gets a few hundred players a day.

Percentile Calculation

With the total attempt count and your rank, percentile is straightforward. Display it as "Top X%" on the result card. Makes every player feel competitive even when they lost.

Cost

Free tier covers it entirely. Neon's free plan includes 0.5 GB storage, 190 compute hours per month, and unlimited reads. A leaderboard game with a few thousand daily submissions stays well within limits.

Total infrastructure cost for a global multiplayer game: zero.

Get the next entry by mail
One mail when a new entry lands. No spam. Unsubscribe anytime.
RAXXO Studios

Written by

RAXXO Studios

One designer in Berlin, close to twenty years in. I build tools with AI, use them daily, and write down what happened.

Share this entry

X LinkedIn
All entries