What if I told you that you could serve over 4.5 million API requests to 3,000 unique users in a month, handle traffic spikes of 400,000 requests per hour, and maintain 100% uptime, all for the grand total of a $10 domain registration fee?
That's not a hypothetical; that's the reality of running swapi.info, a passion project born from the ashes of the original, now-defunct Star Wars APIs. In a world where swapi.dev
has been down for months with SSL issues and other alternatives are slow, ad-ridden, or unreliable, swapi.info
has risen to become a top search result for Star Wars API, providing a fast, free, and dependable resource for developers everywhere.
This is the story of how a clever combination of Next.js, Vercel, and Cloudflare's free tiers created a serverless powerhouse.
The Philosophy: Static First, Always On
The goal was simple: create a Star Wars API that was lightning-fast, completely free, and would remain online for the next generation of developers. The original SWAPI was a huge part of my own learning journey, and I wanted to give back.
To achieve this without a budget, the architecture had to be incredibly lightweight and scalable. This meant no traditional servers, no databases, and no complex backend logic. The answer was to go static.
The entire Star Wars dataset was processed into a collection of simple JSON files. A planet, a person, a starship—each is just a .json
file sitting in a directory. Simple, portable, and incredibly fast to serve.
The Stack: A Modern Serverless Trio
- Next.js: The foundation is a static Next.js application. It provides the API explorer UI and, more importantly, the routing infrastructure.
- Vercel: The app is deployed on Vercel's free tier. Their global edge network is perfect for serving the Next.js frontend with incredible speed.
- Cloudflare: The secret sauce. Cloudflare sits in front of Vercel, providing DNS, proxying, and, most critically, a powerful caching layer.
The "Magic": Turning Static Files into a Clean API
Serving /api/planets/1.json
works, but it's not a clean API experience. Developers expect https://swapi.info/api/planets/1
.
This is where Vercel's configuration comes in. By using rewrites in vercel.json
, we can map clean URL paths to the underlying static JSON files. The configuration is beautifully simple:
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "/api/:path*.json"
}
]
}
With this rule, a request to /api/planets/1
is internally rewritten by Vercel to serve the static file at /public/api/planets/1.json
. The end-user sees a clean API route, but we get the performance and cost-effectiveness of serving a static file.
The Scalability Engine: Bypassing Limits with Cloudflare
Here's the crux of the problem: Vercel's generous free tier allows for 1 million edge requests per month. While amazing, it's not enough to handle the 4.5 million requests swapi.info
now serves.
This is where Cloudflare becomes the hero.
By pointing the swapi.info
DNS to Cloudflare and enabling its proxy, all traffic first hits Cloudflare before it ever reaches Vercel. Then, I applied one simple but powerful cache rule:
For any request where the URL path starts with /api/
, set the Cache Level to Cache Everything
.
The effect is transformative:
- The very first time someone requests
/api/planets/1
, the request passes through Cloudflare to Vercel. - Vercel serves the static JSON file with the appropriate
Cache-Control
headers. - Cloudflare caches this response in its massive global network.
- Every subsequent request for
/api/planets/1
, from anywhere in the world, is served directly from the nearest Cloudflare edge location—in under 50ms.
Vercel's infrastructure is only touched for cache misses or for serving the non-API frontend pages. The result? Of the 4.5 million API requests last month, over 99% were served by Cloudflare's cache, keeping me well within Vercel's free tier limits. This architecture effortlessly handled a massive, hour-long traffic spike of over 400,000 requests without a single hiccup.
A Blueprint for the Future
The success of swapi.info
is a testament to the power of modern serverless platforms. It's a blueprint for any developer looking to launch a high-traffic passion project without breaking the bank. By thinking statically and leveraging the strengths of free-tier services like Vercel and Cloudflare, you can build resilient, scalable applications that serve a global audience.
The project is fully open-source on GitHub, and I invite you to explore the code, use the API, and see what you can build. May the force be with you.
Top comments (0)