Know how we scale our url to millions
Our achieve here is that you url never goes down, so we follow some steps:
-
Unlimited URLs: To provide millions of url we need a way to pass this estimative, so we use nanoid, with your params we garante ~919 years or 8B IDs needed, in order to have a 1% probability of at least one collision.
-
Mongo is a religion: For storage this urls we need a huge database and fast too, so MongoDB Running at atlas to garante and globally distributed data storage.
-
Everywhere in the world: If we have a globally storage we need a way to provide it to every place in the world this is why we pick Vercel as your CDN, using Edge Network we provide this app and the redirects for multiple regions around the world.
-
Unlimited Redirects: And if the redirect goes down? We use Next.js working with SSR and Vercel Functions to provide a huge and unlimited serverless backend.
-
Almost Unlimited: Yes, we have a rate-limit only set in production, this is for prevent to many url created hourly. And to set it we use a Sliding Window Strategy.
-
Security: Nothing more sad than a million service without security for that we use also Vercel WAF, that able us to block and monitor everything it's happen in the network. Also we have a huge captcha to block flooders.
git clone https://github.com/Ellathet/million-shortener.git
cd million-shortenerpnpm installCopy the example environment file and fill in the required values:
cp .env.example .envEdit .env and set the following variables:
MONGODB_URI- MongoDB connection string (e.g.,mongodb://localhost:27017/)NEXT_PUBLIC_RECAPTCHA_SITE_KEY- Your Google reCAPTCHA site key (production)RECAPTCHA_SECRET_KEY- Your Google reCAPTCHA secret key (production)REDIS_URL- Redis URL (production)REDIS_TOKEN- Upstash Redis token (production)
pnpm devOpen http://localhost:3000 with your browser to see the result.
You can run the app and MongoDB using Docker Compose, after install the packages we can run:
docker-compose up --buildThis will:
- Build the Next.js app using the
Dockerfile - Start a MongoDB container
- Expose the app on http://localhost:3000
The MONGODB_URI is set automatically for the app container to connect to the MongoDB service.
Press Ctrl+C in the terminal, then run:
docker-compose downsrc/app/- Next.js app directorysrc/lib/- Utility libraries (MongoDB, reCAPTCHA, etc.)src/models/- Data modelssrc/components/- React components
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.

