Search index
Amazon OpenSearch Service
An inverted index for full-text search, filters, facets and relevance ranking.
In a monolith
LIKE '%term%' on the DB
Search starts as SQL LIKE queries or Postgres full-text — fine until it scans millions of rows on the primary.
In a distributed system
Dedicated search cluster
A search index fed from the source of truth through change events; queries hit the index, never the primary DB.
On AWS
Amazon OpenSearch Service
Managed OpenSearch (Elasticsearch-compatible) clusters or OpenSearch Serverless, with ingestion pipelines from streams/CDC.
- OpenSearch Service (managed cluster)$$$Sized data nodes, Multi-AZ
- OpenSearch Serverless$$$No cluster sizing; higher minimum cost
- Reach for it when
- Users need text search, typo tolerance, filters and ranking at a scale where DB queries get slow.
- What it costs you
- Eventually consistent with the DB (indexing lag)
- Another stateful cluster to size and operate
- Reindexing when mappings or analyzers change
- When it dies
- Search goes down, but browsing by ID still works if pages don’t depend on it — degrade gracefully.
Interview follow-ups
How do you keep the index in sync with the DB?
CDC or outbox events consumed by an indexer. That avoids the lost updates you get from dual writes when one of the writes fails.
Why not search the primary DB?
Relevance-ranked full-text over millions of rows needs inverted indexes; doing it on the primary competes with transactional traffic.
Connection rules
It talks to
Gets traffic from
- App server
- Service
- Worker
- Realtime server
- Event streamOnly when: Managed ingestion (e.g. OpenSearch Ingestion) indexing straight from a stream.
Never
- Clients → SearchSearch clusters aren’t public: queries go through your API for auth, rate limits and query shaping.
- CDN → SearchCDN origins are HTTP servers or buckets, never databases or caches.
- Load balancer → SearchA load balancer forwards HTTP to compute. Data access needs code: auth, queries, validation.
- API gateway → SearchA gateway routes to compute; data access needs your code.
- Queue → SearchQueues don’t run code. A consumer reads the message and does the write or call.
- Pub/sub topic → SearchTopics don’t run code. A subscriber receives the event and does the write.