Skip to content
yisusvii
Go back

AI Backends: Cosmo Federation & Apollo Subgraphs on EKS

Suggest Changes

Table of Contents

Open Table of Contents

Why AI Changed the Shape of the Backend

For a decade, the default backend conversation was about REST endpoints, service boundaries, and relational schemas. AI workloads broke that default in a quiet but structural way.

An AI feature is rarely a single request against a single table. A useful answer usually needs identity, permissions, entity data, semantic search results, aggregated history, and often a model call — assembled into one coherent response with predictable latency and cost.

That is a composition problem, not a database problem. This is exactly why federated GraphQL has become the practical backbone of modern AI backends: it gives agents and clients one typed contract over many domain services, while each team keeps ownership of its own subgraph.

The stack discussed here is deliberately boring in the best sense:

Client / Agent / Copilot surface
        |
        v
WunderGraph Cosmo Router (federated supergraph)
        |
        +--> Subgraph: catalog     (Apollo Server 4 / Express / TypeScript)
        +--> Subgraph: identity
        +--> Subgraph: ai-insights
        |
        v                        (running on AWS EKS)
DynamoDB (ElectroDB)  +  OpenSearch  +  model providers

Every layer has one job. The router composes. The subgraph owns a domain. DynamoDB owns durable entity state. OpenSearch owns retrieval. The model provider owns generation.


1. Cosmo as the Federation Layer

WunderGraph Cosmo is an open-source implementation of GraphQL Federation: a router, a schema registry, composition checks, analytics, and a control plane you can self-host.

The reason it matters for AI backends is that federation solves the “one endpoint, many owners” problem without turning the gateway into a monolith of hand-written resolvers.

What the router actually provides:

The AI-specific advantage is underrated: an LLM agent works dramatically better against a self-describing, typed graph than against a set of loosely documented REST endpoints. The schema is the tool definition. Field descriptions become the prompt context. Persisted operations become the allowlist of safe actions.

Self-hosted vs Cosmo Cloud

ConcernSelf-hosted CosmoCosmo Cloud
Data residencyFull control, stays in your VPCManaged control plane
Operational loadYou run router, control plane, ClickHouseManaged
Cost modelInfrastructure costSubscription
Best forRegulated workloads, existing EKSSmall platform teams

For teams already running EKS, the self-hosted router is a normal stateless deployment: a container, a config, an HPA, and an ingress.

Router on EKS

The router is CPU-bound and stateless, which makes it a well-behaved Kubernetes citizen:


2. The Subgraph: Apollo Server 4, Express and TypeScript

Each domain is an Apollo Server 4 subgraph. Apollo Server 4 dropped the built-in framework integrations, so the Express wiring is explicit — which is a benefit, because AI workloads need middleware you actually control.

What belongs in the subgraph:

What does not belong in the subgraph:

Federated Entities

The @key directive is what makes composition work. A Product defined in the catalog subgraph can be extended by the ai-insights subgraph with a summary or recommendations field, resolved by reference. The client asks one question; the router fans out.

This is the pattern that keeps AI features from contaminating core domains. AI-generated fields live in an AI subgraph with their own SLOs, their own timeouts, and their own failure mode: a null field with an error extension, not a failed page load.

Latency Discipline

An AI subgraph must be explicit about time budgets:


3. DynamoDB with ElectroDB as the Entity Store

DynamoDB is a strong fit for AI backends because the access patterns are known and the traffic is spiky. What it is not good at is being modeled ad hoc.

ElectroDB solves the part teams usually get wrong: it gives TypeScript-typed entity and service definitions over single-table design, generating the key composition, index mapping, and query builders instead of leaving them as string concatenation in application code.

Why this pairing works with a subgraph:

Rules that survive production:

  1. Design the access patterns from the GraphQL operations, not from an ER diagram.
  2. Keep partition keys tenant-scoped for isolation and hot-key avoidance.
  3. Use sparse GSIs for filtered listings instead of scanning.
  4. Store generated AI artifacts (summaries, embeddings metadata, evaluations) as separate entities with a version and TTL, never as mutations to source records.
  5. Use on-demand capacity until traffic shape is genuinely known.

The last point is important for AI features specifically. Generated content must be traceable: which model, which prompt version, which source revision. Overwriting the source record destroys that audit trail.


4. OpenSearch as the Retrieval Layer

DynamoDB answers “give me this entity.” OpenSearch answers “give me the relevant ones.” AI backends need both.

Amazon OpenSearch Service supports lexical search, k-NN vector search, and hybrid search that blends the two. Hybrid is usually the right default: pure vector search misses exact identifiers, part numbers, and error codes, while pure lexical search misses paraphrase.

Indexing pipeline:

DynamoDB table
    |
    v  DynamoDB Streams
Lambda / consumer  --> normalize + chunk --> embed --> OpenSearch index
                                                          |
                                                          v
                                            ai-insights subgraph (hybrid query)

Operational guidance:


5. Putting It Together on EKS

A realistic deployment layout:

ComponentDeploymentScaling signal
Cosmo RouterDeployment, 3+ replicasCPU + request concurrency
Domain subgraphsDeployment per subgraphCPU + p95 resolver latency
AI subgraphDeployment, separate node poolInference queue depth
Stream consumersDeployment or LambdaStream iterator age

Platform details that matter:


6. Security and Governance

AI backends widen the blast radius of a bad authorization decision, because a single query can compose data from several domains and then feed it into generation.


7. Migration Path

Phase 1: Establish the Graph

Phase 2: Model the Data Properly

Phase 3: Add Retrieval

Phase 4: Add AI Fields Safely


Summary

The new era of AI backends is not defined by which model you call. It is defined by how cleanly you compose data, retrieval, and generation behind one typed contract.

Cosmo provides the federation layer and governance. Apollo Server 4 subgraphs on EKS keep domain ownership intact. DynamoDB with ElectroDB gives predictable, typed entity access. OpenSearch supplies hybrid retrieval with permission-aware filtering.

The architecture works because each layer stays replaceable. Model providers will change. Retrieval strategies will change. A federated graph over well-modeled entities is the part that survives.


Suggest Changes
Share this post on:


Previous Post
Debugging Production with Cloud CLIs and AI Agents
Next Post
FinOps for Centralized AWS Bedrock AI Cost Allocation