This article discusses the architectural challenges of building multi-tenant search applications using Amazon OpenSearch Service, particularly when scaling to millions of tenants. It highlights common pitfalls of adopting pure logging or pure search strategies and proposes a hybrid approach combining custom document routing, dedicated indices for large tenants, and intelligent tiering.
Read original on Dev.to #architectureMulti-tenancy in search applications, where each customer or entity has isolated data, introduces significant scaling challenges. Designs that work for hundreds of tenants often fail at hundreds of thousands or millions, leading to slow queries and ballooning costs. This problem is particularly acute in user-facing applications like fintech, where instant access to historical data is critical.
The Million-Tenant Dilemma
Conventional wisdom often forces a choice between optimizing for cost or latency. At a million tenants, both are critical, making standard playbooks insufficient.
The key to scaling multi-tenant search is acknowledging that not all tenants are equal and routing requests to dedicated resource slices. This involves a hybrid strategy combining shared resources with custom routing for smaller tenants and dedicated resources for larger, 'whale' tenants.
For the vast majority of small tenants sharing indices, custom document routing is crucial. By default, OpenSearch distributes documents using a hash function, spreading a tenant's data across many shards. Custom routing allows specifying a tenant ID as the routing key, ensuring all data for a given tenant lands on a single (or a small subset of) shards. This dramatically reduces query fan-out, cutting networking costs and latency by up to 98% at scale. This becomes critical beyond tens of thousands of tenants. For larger tenants within a shared pool, `index.routing_partition_size` can spread data across a predefined subset of shards to balance load.
For 'whale' tenants with high query volumes and specific isolation needs, a dedicated slice of resources is essential. This can range from a dedicated index within the same domain to an entirely separate OpenSearch domain (a "cell architecture") or even a dedicated collection in OpenSearch Serverless. This isolation prevents large tenants from impacting the performance of smaller tenants.
Mixed workloads (write-heavy ingestion and read-heavy queries) require a balanced approach to shard sizing. Instead of 50GB for pure logs or 10-30GB for pure search, aiming for 30-40GB per shard typically balances ingestion throughput and query performance effectively. Furthermore, modern "writable warm storage" (like OpenSearch Optimized OI2 instances) addresses the mutability limitations of older UltraWarm tiers. It offers S3-backed storage with local caching and allows direct writes to warm data, resolving late-arriving data or corrections in seconds without costly migration round-trips to hot storage.