Zero Labs
Industry News / AI

Building a Search Microservice for 1M Products and 15M+ Daily Requests

Source · Towards AI By Mehedi Hasan

From the publisher’s feed, collected in the ZeroLabs newsroom.

I built a product search microservice for 1 million products using FastAPI, OpenSearch, Redis, PostgreSQL, and Nginx. It sustained ~180 QPS on just 2 CPU cores and 12 GB RAM.A search box looks simple.You type a few words, press Enter, and a list appears. How hard could it be?Then you put one million real products behind it. Add thousands of brands. Add users who can’t spell. Add hundreds of them hitting it at the same time. Add a hard rule that every answer has to come back in a few milliseconds, on a server so small it’s free.Now it’s a different problem entirely.That’s the project. A product search service that stays fast and typo-tolerant across a million-item catalog, running inside the smallest budget I could give it. Type “wireles keybord” — misspelled twice — and the right products come back in about 3 milliseconds, before your finger leaves the key.Here’s what it does, measured under load:~180 searches per second sustained — roughly 15 million a day~1,046 per second at its ceiling before it saturates~3 ms for a repeated query, ~13 ms for one it has never seen0% errors across every final testAll of it on 2 CPU cores and 12 GB of RAM — a free-tier cloud VMBut the numbers aren’t really why I’m writing this.I built it to answer a question that’s been nagging at me.The real reason I built thisI work with AI. And I can watch an AI agent write a working search endpoint in about ten seconds. So can you. So can anyone with the tool open.Writing the code isn’t the hard part anymore. That ship has sailed, and honestly, good riddance.But a search system isn’t a piece of code. It’s five different programs — a database, a search engine, a cache, a gateway, and the app that ties them together — each doing one job, all talking over a network. And an AI will cheerfully generate any one of those pieces while handing you a design that quietly falls apart the moment real traffic arrives. It doesn’t know which decisions are load-bearing.The code got cheap. The judgment didn’t.So this became less about “can I build a search service” and more about the thing AI can’t do for you yet: decide what the system should be made of, and prove it holds up.Let me show you what that looks like in practice.A search engine is a team, not a programIf “microservice” sounds like buzzword soup to you, here’s the whole idea in one image.Picture a busy restaurant kitchen.The pantry stores every ingredient, reliably, losing nothing. → the database, PostgreSQLThe line cooks turn raw ingredients into finished plates, fast, all at once. → the search engine, OpenSearchThe pass keeps the most-ordered dishes ready under the lamp. → the cache, RedisThe host at the door decides who comes in and how fast. → the gateway, NginxThe head chef takes each order and coordinates everyone. → the app, FastAPINo one person runs the restaurant. The skill is in how the roles fit together.You ──► Nginx ──► FastAPI ──► Redis (cache) (gateway) (the chef) │ ▼ OpenSearch (search) ▲ PostgreSQL (truth)The part that matters: these pieces are not interchangeable. Each exists because it solves a problem the others can’t. And the interesting engineering isn’t in any single one. It’s in the rules between them.The pantry never plates food. PostgreSQL holds the real, authoritative data, but it never answers a search. Searching a database directly across a million rows is slow. So the data is copied into OpenSearch, which is built for exactly that kind of lookup.The pass can be wiped clean anytime. Redis holds recent results for speed, but stores nothing permanently. If it dies, the next search is a few milliseconds slower and that’s the entire consequence. That “it’s fine to lose it” decision is why the cache is allowed to be so fast — it never stops to save anything to disk.The cooks need empty counter space. OpenSearch gets only half its memory for its own work. The other half stays free on purpose, because the engine leans on the operating system’s file cache to stay quick. The tempting move — give it all the RAM! — actually makes it slower and can crash it.In plain terms: the value isn’t “I built a search box.” It’s knowing why the database, the cache, and the search engine each exist, and what breaks if you use the wrong one for the job.That last one is a good example of the trap. Ask an AI to “maximize OpenSearch performance” and there’s a real chance it hands you a config that gives the JVM all the memory and gets the container killed under load. The setting looks like an optimization. It’s a landmine. You only know that if you understand how the layers underneath actually behave.The journey of a single searchEvery request takes the same path:query │ ▼ cached already? ├─ yes ──► return the saved answer (~1 ms) └─ no ──► ask OpenSearch, save it, returnMost people search for the same popular things. So the cache answers the bulk of traffic almost instantly, and only genuinely new queries ever reach the search engine. That single idea is the biggest reason this runs on such small hardware.There are actually two cache layers. A tiny one lives inside the app itself — no network hop at all — backed by the larger shared Redis. Think of the chef keeping three dishes right at their station, with the warming pass behind them. Together they soak up repeat traffic before it becomes real work.Do the expensive thing only when you actually have to.Real data, because fake data liesI didn’t want a toy dataset. Clean synthetic data is polite. It hides every problem you’ll hit for real.So I used a public catalog of real Amazon listings and pulled exactly one million products from it, across electronics, home, and sports, plus the ~29,000 brands behind them.Real data fought back immediately. The source files looked like standard data but weren’t — they used a Python-specific format that the obvious parser chokes on, silently, line after line. Prices came formatted five different ways. Titles carried junk. Fields went missing. Handling that mess is the job, and you only meet it with real data.Then there are the users, who also don’t cooperate:wireless keyboard → wireles keybordbluetooth speaker → blutooth speakrA search that only matches perfect spelling is useless in the real world. So the service uses fuzzy matching to absorb typos. But the real decision isn’t “turn on fuzzy search.” It’s deciding how forgiving to be.The system allows two typos in a long word, one in a medium word, and none in a two-letter query. Because at two letters, “cat” and “car” aren’t typos of each other. They’re different things. Forgiveness that feels smart on long words turns into nonsense on short ones. Tuning that line is the difference between helpful and infuriating.Then I tried to break itThis is the part I cared about most, and the part most portfolio projects skip.Anyone can run one test, watch it go green, and call it done. I ran eight load tests, escalating from a gentle warm-up to a thousand users at once.Seven passed clean. Fast, zero errors. I could have stopped there and shown you a wall of green checkmarks.The eighth was built to be cruel. I generated 29,811 unique misspelled queries — every single one different — specifically so the cache couldn’t save me. Every request would have to do real work.It failed 69.5% of requests.And that was the most useful thing that happened in the whole project.Because a heavily cached benchmark is a comfortable lie. If almost every test request is a cache hit, you’re not measuring your search system. You’re measuring Redis. The cruel test stripped that comfort away, and two real bugs fell out immediately:The cache reader was counting results using a field name left over from an earlier version of the code. Every single cache hit threw an error. Invisible under normal traffic, fatal the moment the cache actually got used at scale.The Redis connection pool was sized for calm days — 50 connections. Three hundred users all missing the cache at once drained it instantly. Too many connections.Neither was visible on the happy path. Both were waiting for exactly the kind of day you don’t want them to surface.A passing benchmark doesn’t mean your system is solid. It might just mean you tested the easy path.I fixed both, re-ran everything, and got a clean board. Here’s where it landed.Two of those eight scenarios are the ones that actually answer the design question. B is sustained traffic with a warm cache: P95 of 3.2 ms. G is sustained traffic where every query is new — no cache to hide behind — and it still holds 13 ms at 179 requests a second. Against a 100 ms target, that’s a comfortable margin on both the easy path and the hard one.And every number was measured with the machine deliberately throttled to that 2-CPU / 12 GB budget. It would have been easy, and dishonest, to benchmark on my full desktop and quote numbers that could never survive on the real target.A benchmark without its constraints is just a good-looking fiction.The constraint was the whole pointI could have run this on a big machine and made the performance problems disappear with brute force. That’s the boring solution, and it teaches you nothing.The 2-CPU budget forced every decision to matter. When the search engine and the app are fighting over two cores, you can’t paper over a bad design. You have to understand where the time and memory actually go — the OpenSearch memory split, the two cache layers, keeping the database out of the read path entirely.Resource allocation is architecture. Performance isn’t only about faster code. It’s about how memory, disk, network, caching, and concurrency push against each other.Anyone can make software fast on a large server. Making a million-row search feel instant on the smallest free VM there is — that’s where the real decisions live. The tight budget wasn’t a limit on the project. It was the project.So what’s the engineer for?This is the question I started with, and building the thing sharpened my answer.An AI agent can generate a database query. But should the database be answering searches at all?It can configure a cache. But which data is safe to cache, and what happens when the cache is gone?It can set up a search index. But how much memory should it get, and why is “all of it” the wrong answer?It can write a load test. But does that test hit the failure mode you actually care about, or just the one that looks green?Every one of those questions is about the system as a whole, not any single piece. And every one of them, in this project, was where the real work happened. Not in typing the code. In deciding what the code should be, and then trying to break my own decisions before the world did it for me.There’s a flip side worth saying out loud. If generating code gets cheap, verification gets more valuable, not less. The more an agent produces, the more someone has to define the requirements, choose the boundaries, spot the failure modes, and prove it holds. Reading a spec critically caught a caching bug in this one before I wrote a line — a design that truncated its cache keys and would have quietly served people each other’s results. An afternoon of reading, versus a production incident.And good engineering means being honest about the edges. This isn’t a globally distributed platform. It’s one machine. No zero-downtime deploys, no auth, no multi-region cluster. Naming those limits is what makes the claims inside them trustworthy. A project that only lists strengths reads like marketing. One that knows its own boundaries reads like engineering.A search box is easy.A search system is not.The code, increasingly, can be generated. The engineering decisions still have to be understood. That gap is the job now — and I think it’s a more interesting job than it’s ever been.The full project — code, architecture notes, the spec issues I caught before building, and all eight load tests — is on GitHub. Built with FastAPI, OpenSearch, Redis, PostgreSQL, and Nginx, and designed to fit Oracle Cloud’s free tier.If you build with AI agents too: what’s the hardest engineering decision you still insist on making yourself? I’d genuinely like to hear it.Building a Search Microservice for 1M Products and 15M+ Daily Requests was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.