Close Menu
geekfence.comgeekfence.com
    What's Hot

    What happens to MAHA after MAGA?

    June 25, 2026

    Long-Haul Networks and Bandwidth Growth

    June 25, 2026

    Scaling cybercrime disruption through innovation and AI

    June 25, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Big Data»Implement multi-tenant search with Amazon OpenSearch Serverless next generation
    Big Data

    Implement multi-tenant search with Amazon OpenSearch Serverless next generation

    AdminBy AdminJune 25, 2026No Comments7 Mins Read0 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Implement multi-tenant search with Amazon OpenSearch Serverless next generation
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Learn how to implement cost-effective multi-tenant search using Amazon OpenSearch Serverless next-generation architecture with scale-to-zero compute and simplified routing through per-account, regional endpoints.

    Building multi-tenant search architectures requires balancing data isolation with operational cost and complexity. In this post, we provide code examples for an implementation of multi-tenant search using a collection-per-tenant model with Amazon OpenSearch Serverless per-account, regional endpoints. Collection-per-tenant provides data and workload isolation. The regional endpoint simplifies routing requests for indexing and searching data.

    Amazon OpenSearch Serverless is a serverless deployment option for Amazon OpenSearch Service that simplifies infrastructure management, index tuning, and data lifecycle management. OpenSearch Serverless automatically provisions and scales resources to provide consistently fast data ingestion rates and millisecond query response times during changing usage patterns and application demand.

    The multi-tenant search problem

    In search workloads, a tenant is a logical unit of data and the queries against that data. An eCommerce site has product categories. Each category is a tenant. A blog-hosting platform has blogs. Each blog is a tenant. Tenants map to resources in different ways. In the siloed model, each tenant gets its own container: a domain, collection, or index. In the pooled model, tenants share a container. The hybrid model silos large tenants and pools smaller ones together. Regardless of model, you need a mapping between tenant identifiers and the containers that hold their data, so your application routes requests correctly.

    OpenSearch Serverless classic offered a collection-per-tenant strategy that simplified, but did not remove, the need for maintaining a tenant-container mapping. In addition, the cost structure of maintaining collection-per-tenant in classic was not ideal. Classic shared hardware across collections with the same AWS Key Management Service (AWS KMS) key. Tenants with different keys could not share hardware. The cost of the solution was the minimum monthly collection cost multiplied by the tenant count. Building for hundreds or thousands of tenants was cost-prohibitive. Collection groups improved this by allowing hardware sharing across AWS KMS keys, but compute costs were still driven by your indexed data, even during idle periods.

    With the next-generation architecture, collection groups scale compute to zero. You pay for compute only when a tenant is actively indexing or searching (storage charges still apply). The addition of the regional endpoint further simplifies multi-tenant workloads by routing traffic to any collection through a single hostname. Together, scale-to-zero compute and the regional endpoint make the collection-per-tenant model both economically viable and operationally straightforward.

    The OpenSearch Serverless per-account endpoint

    OpenSearch Serverless next generation introduces a per-account, regional endpoint that serves all collections through a single hostname:

    https://.aoss..on.aws

    The x-amz-aoss-collection-name or x-amz-aoss-collection-id header identifies the target collection on each request. This means one connection pool, one TLS session, and one endpoint to manage regardless of how many collections you have.

    From a client perspective, you create a single OpenSearch client pointed at the regional endpoint and route requests by setting a header:

    def get_opensearch_client(account_id: str, region: str) -> OpenSearch:
        """Create an OpenSearch client using the regional endpoint."""
        host = f"{account_id}.aoss.{region}.on.aws"
        auth = get_aws4auth(region)
    
        return OpenSearch(
            hosts=[{"host": host, "port": 443}],
            http_auth=auth,
            use_ssl=True,
            verify_certs=True,
            connection_class=RequestsHttpConnection,
            timeout=60,
        )

    Every subsequent request includes the routing header to target a specific collection:

    headers = {"x-amz-aoss-collection-name": collection_name}

    This is a significant improvement over the classic architecture, where each collection had its own endpoint and you needed to manage separate connections for each.

    Collection per tenant with query routing

    The architecture is straightforward: one collection group holds all tenant collections, and the regional endpoint handles routing.

    Create a collection group with scale-to-zero

    client.create_collection_group(
        name="amazon-pqa-cg",
        generation="NEXTGEN",
        standbyReplicas="ENABLED",
        capacityLimits={
            "minIndexingCapacityInOCU": 0,
            "maxIndexingCapacityInOCU": 8,
            "minSearchCapacityInOCU": 0,
            "maxSearchCapacityInOCU": 8,
        },
    )

    When you set minIndexingCapacityInOCU and minSearchCapacityInOCU to 0, OpenSearch Serverless scales down your compute to 0 OpenSearch Compute Units (OCUs) when they are idle for 10 minutes. You pay only for the storage for your indices. If you want to maintain compute and avoid cold starts, set minIndexingCapacityInOCU or minSearchCapacityInOCU to a value greater than 0.

    Create one collection per tenant

    Each product category maps to its own collection within the group:

    client.create_collection(
        name=name,
        type="SEARCH",
        collectionGroupName=COLLECTION_GROUP_NAME,
    )

    When choosing a collection name for your tenants, consider privacy, name length, and future ease of upgrading your application. You can use a hash function to map tenant identifiers to collection names.

    import hashlib
    
    def collection_name_for_tenant(tenant_id: str) -> str:
        """Generate an opaque collection name from a tenant identifier."""
        return hashlib.sha256(tenant_id.encode()).hexdigest()[:16]

    Collection names are visible in API calls and logs. If your tenant ID contains personally identifiable information (PII), that information is also visible in logs. Hashing the tenant ID obfuscates the sensitive information.

    OpenSearch Serverless has a 64-character limit on collection names. Your tenant ID can be longer than that. Hashing helps stay within this limit.

    You might also want to add a prefix to collection names so that you can use wildcard patterns in access policies. For example, naming collections pqa-a1b2c3d4 lets you write a single data access policy matching collection/pqa-*. Including a version component in the name (such as pqa-v2-a1b2c3d4) makes it straightforward to create new collections during schema migrations without disrupting existing tenants.

    Index data using the regional endpoint

    A single OpenSearch client handles all collections. The x-amz-aoss-collection-name header routes each request to the correct collection:

    headers = {"x-amz-aoss-collection-name": collection_name}
    
    # Build bulk request
    action = {"index": {"_index": index_name, "_id": doc["question_id"]}}
    batch.append(json.dumps(action))
    batch.append(json.dumps(doc))
    
    # Send bulk request routed to the target collection
    body = "\n".join(batch) + "\n"
    resp = os_client.bulk(body=body, headers=headers)

    Query a specific tenant’s data

    Searching works the same way. Set the header to target the tenant’s collection:

    os_client = get_opensearch_client(account_id, region)
    headers = {"x-amz-aoss-collection-name": collection_name}
    
    query = {
        "size": 3,
        "query": {
            "match": {
                "question_text": "4k resolution hdmi"
            }
        },
    }
    
    resp = os_client.search(index="questions", body=query, headers=headers)

    The application layer maps a tenant ID (in this case, a product category) to a collection name, and the regional endpoint handles the rest. No connection pool management, no endpoint lookups, no per-tenant client instances.

    Limitations

    There are practical constraints to consider when adopting this pattern.

    Cold start latency. When a collection group has scaled to zero compute, the first request takes approximately 10 seconds while capacity provisions. For latency-sensitive tenants, you can send a lightweight warmup query (such as a match_all with size=1) before production traffic arrives.

    Collection group limits. There are account-level limits on the number of collections and collection groups. Check the Amazon OpenSearch Serverless quotas for current numbers if you are planning thousands of tenants.

    Security policy size. Encryption, network, and data access policies list collection resource patterns. Because tenant count grows, these policy documents grow linearly. Use wildcard patterns to stay within OpenSearch Serverless policy size limits.

    No cross-collection queries. Each search request targets exactly one collection. If you need to query across tenants for analytics or global search, you need an aggregation layer or a separate shared collection.

    Conclusion

    In this post, we showed how the next-generation OpenSearch Serverless architecture makes the collection-per-tenant model practical for multi-tenant search. Scale-to-zero reduces the minimum cost for inactive tenants, fitting the compute resources to the demands of tenants. The regional endpoint eliminates the operational complexity of managing per-tenant connections. You get full data isolation between tenants, independent scaling for each tenant’s workload, and a single endpoint to manage in your application code.

    For more information, see the Amazon OpenSearch Serverless documentation.


    About the author

    Jon Handler

    Jon Handler

    Jon is a Senior Principal Solutions Architect for Search Services at Amazon Web Services. Jon works closely with OpenSearch and Amazon OpenSearch Service, providing help and guidance to a broad range of customers who have search and log analytics workloads. Prior to joining AWS, Jon’s career as a software developer included four years of coding a large-scale, eCommerce search engine.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Databricks positioned highest in execution and furthest in vision for the second consecutive year in Gartner Magic Quadrant

    June 24, 2026

    New Data Analytics Breakthroughs Give Ecommerce Startups a Fighting Chance

    June 23, 2026

    Google Spent $2.7 Billion to Keep Noam Shazeer, OpenAI Got Him Anyway |

    June 22, 2026

    Machine Learning System Design: 10 Interview Problems Solved

    June 21, 2026

    How the Precisely MCP Server Brings Location Intelligence Directly Into Your AI Workflows

    June 20, 2026

    AI-assisted data development with Kiro and SageMaker Unified Studio

    June 18, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202555 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202630 Views

    Redefining AI efficiency with extreme compression

    March 25, 202628 Views
    Don't Miss

    What happens to MAHA after MAGA?

    June 25, 2026

    Donald Trump is not exactly a health influencer: The 47th president famously loves fast food…

    Long-Haul Networks and Bandwidth Growth

    June 25, 2026

    Scaling cybercrime disruption through innovation and AI

    June 25, 2026

    Implement multi-tenant search with Amazon OpenSearch Serverless next generation

    June 25, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    What happens to MAHA after MAGA?

    June 25, 2026

    Long-Haul Networks and Bandwidth Growth

    June 25, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.