A few days in my work: building a multilingual search API on AWS

A few days in my work: building a multilingual search API on AWS

People sometimes ask what my work looks like day to day. The honest answer is that most of it sits between a database and a person waiting for a result, and most of the hard parts are about data, not code. Here is one piece of recent work, a multilingual search API on AWS, told the way it happened: one day, one problem.

The job was to replace two older search tools inside a monolith with one read-only service. It had to answer both kinds of search, work in many languages, stay in step with the source database, and add no load to it.

The day we drew the whole path

None of this was a solo effort. We worked as a small team in Scrum, with stand-ups, sprint planning and reviews, and most of the decisions below came out of discussion in those meetings. In one of the early design sessions we wrote the full path of a single change on one line:

source database → AWS DMS → Kinesis → ingest Lambda → our Postgres store → indexer → OpenSearch → search service → public API → Cloudflare → website

Having that line on the screen for everyone gave us a shared map. When someone said "the ingest", we all meant the same box. From it we agreed to split the work into two services, in two repos, deployed separately. The search service owns everything about the indexes: the pipeline from the source, our own Postgres store, the ingestion Lambdas and every OpenSearch query. The public API validates requests, builds the response and calls Google Places. It never talks to OpenSearch. The index mappings are copied into the API repo and checked in CI, so changing a call means two pull requests, search service first. Changes take a little longer, and breakage is much rarer.

A lot of the trickier code, like the ordering in the ingest and the locking, I wrote in pair programming sessions with colleagues. Two people looking at the same lock order catch things that one person reading a pull request later tends to miss.

The day we picked boring infrastructure

  • Go for the services and the Lambdas. We started with a Python prototype and moved to Go once the shape was clear.
  • Amazon OpenSearch Service, three Graviton nodes in production, with language analysis plugins so Japanese, Korean, Chinese, Polish and the rest tokenise properly.
  • Aurora Serverless v2 with PostGIS as the store between the source and the indexes.
  • EC2 Auto Scaling groups. We picked them over Fargate for a dull reason: the same image, Compose files and Datadog agent as dev and stage.
  • AWS CDK in TypeScript for infrastructure, CodePipeline for CI, Datadog monitors, SLOs and synthetics managed through Terraform, and Cloudflare in front of both APIs with mutual TLS to the load balancers in production.

The night of nine deadlocks

On dev, the setup step deadlocked with the ingest nine times in one night. Two things fixed it. Setup now skips itself when nothing has changed, using a fingerprint check, and every lock is taken in a fixed order. On top of that, every command and Lambda that writes takes the same Postgres advisory lock, so there is only ever one writer.

The day the first load crawled

Our first full load was slow for a silly reason. A cast, id::text, in the route lookups stopped Postgres from using the index, so every row triggered a full table scan. We fixed the query, and now a test fails if any lookup can't use an index.

The day the load balancer gave up on us

During a load test the load balancer dropped our only search host four times. The health check was hitting an endpoint that did real work, and under load it answered too slowly. It now checks a plain liveness endpoint. Health checks should tell you the process is alive, and nothing more.

The day some queries never cached

OpenSearch's request cache refuses any search that reads now, and a few of ours did. We took now out of every query. Later we added Cloudflare caching of search responses on top, and warmed OpenSearch after each deploy so the first users after a release didn't pay for a cold cache.

The day languages got messy

People pick English as their language and then write in Spanish, German or Polish. So we detect the language from the text and ignore the setting. Sending everything for AI translation is manual only, so a routine deploy never spends credits by accident.

Then the dev subnets lost their NAT gateway, and the translation calls had nowhere to go. We moved them into a small relay Lambda outside the VPC.

The day we wrote the deny-list

One source table carries dozens of financial, legal and personal columns. We never copy them. If one turns up in the change stream anyway, the ingest drops it and raises an alert. At that point it's a data-protection issue that needs a person, and a log line isn't enough.

Load test day

The targets were p95 under 500 ms end to end, errors under 0.1%, 100 requests a second at peak with spikes to 150, and a change in the source visible within 10 minutes.

In a dev trial, a single change reached the live index in about 33 seconds. In the production load runs, one run served 130,359 requests with no failures and a p95 of 101 ms. The next run, with a spike, failed 57 of 130,351 requests (0.044%). Every failure was a 503 from our own in-flight query cap, while OpenSearch sat at 83% CPU. That told us the real ceiling was the search cluster, and the API hosts had room to spare. We kept the cap. A fast 503 is better than a queue that falls over.

Decisions I'd make again

Rebuild, then swap. Every rebuild writes a new index with a build ID in its name, and the API reads through an alias. Going live is one alias swap, and so is rolling back. Checks have to pass before the alias moves, and a full production rebuild takes under four minutes.

Keep a small index on one shard. The main index is about 20 MB. A second shard would have made counts approximate, and people notice when a number on the page doesn't match the list below it.

Use strict mappings. A document with a field the mapping doesn't know is rejected. The alternative is an index that widens without anyone noticing every time a column is added upstream.

Decide existence at build time and visibility at request time. Whether a record exists is baked into the index. Whether it should be shown depends on status data that changes often, so that is checked on every request, and a status change takes effect with no rebuild.

Don't store numbers that depend on a daily rate. Those values stay in their original units and are converted at query time, so a new rate changes no documents at all. Before this, one rate update took 52 minutes to reach the index. Now it lands within a minute.

Make replays boring. The ingest applies a change only if its sequence number is newer than the last one it saw, so replaying the change stream changes nothing. Versions are in microseconds, because two changes within the same second would otherwise get the same version.

My part

Two colleagues owned the architecture and infrastructure, and the data pipeline. I worked across both repos: the split into two services, the change pipeline from DMS to the indexes, the translation work, page lookups and map pins, alarms on the change path, the sitemap and hreflang, and the performance work before launch, which covered OpenSearch warming, the in-flight query cap, coarser map boxes, Cloudflare caching and the k6 test profiles.

Other days: matching messy records

Not every day is about speed. Some of my work is data reconciliation: a batch tool that compares records from several sources against a master list and flags what's new, what's gone and what has changed. Here the job is to be right, not fast.

The toolkit is different. Python with httpx and selectolax for collecting and parsing, and Playwright with a real browser where a page needs one. rapidfuzz, phonenumbers and tldextract for comparing names, numbers and domains, and H3 cells for finding nearby candidates. SQLite in WAL mode to start with, one small Graviton EC2 instance built with Terraform, and deploys from GitHub Actions through OIDC and SSM with no SSH. An LLM through a batch API is an optional extra layer, with a per-run cap and a monthly budget.

A few lessons from those days:

  • Match against the full master list from day one. A sample hides most of the real problems.
  • Closeness is a hint, never proof. Two records near each other are often different things, so an automatic match needs a unique identifier or a strong name match.
  • Make it deterministic. If two identical runs give different answers, look at how ties are broken.
  • Pin dependencies below their next major version. An unpinned parser once shipped a release that removed what we used, and the next deploy broke.
  • The tool flags and people decide. Nothing in the master data changes without a person confirming it.
  • Ask for a labelled set of known matches at the start. Without one you can show a matcher got better, but not how good it is.

What I take to the next project

  • Draw the whole path of one change, as a team, before building any of it.
  • Pair on the tricky parts, and talk designs through in the open.
  • Replays should change nothing.
  • Every change gets a before and after. "It feels faster" isn't a measurement; a load run is.
  • When two sources of data disagree, name the source of truth out loud, in a meeting, before the system picks one for you.
  • Put judgement where it belongs. The index records what exists; the request decides what to show.

The 503s from our own query cap are still my favourite result. The system told us where its limit was, early and cheaply, before any user found it.

If your team is building something similar, on AWS or in Drupal, I'm happy to compare notes, and to put you in touch with Axelerant, where I work. Get in touch.