# Deploy to Production
Source: https://docs.maelstrom-ai.co/0.2/tutorials/deploy-to-production/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

A local Maelstrom demo can run with an in-memory engine, a development WebSocket, and a single provider key. Production needs stricter boundaries: provider credentials stay server-side, history must be durable if you enable it, and the connector path must survive deploys, restarts, and network failures.

This tutorial turns a development setup into a production-shaped deployment checklist. It does not prescribe one hosting provider; it names the boundaries you need to make explicit before shipping.

> [!WARNING]
> Caution
> 
> The bundled `@maelstrom-co/engine` is a reference implementation. Use it to learn the contract, run demos, and build prototypes. For production, decide whether you can operate it with the required history, locking, logging, and safety controls, or whether you should provide your own implementation behind the same `Engine.handle()` boundary.

1.  ## Split browser and server responsibilities
    
    Browser code should render the Chart, capture user intent, and talk to a connector. Server code should own LLM provider keys and the engine implementation.
    
    ```mermaid
    flowchart LR
      subgraph Browser["Browser app"]
        React["@maelstrom-co/react"]
        Connector["@maelstrom-co/client connector"]
        NoSecrets["no provider secrets"]
      end
    
      subgraph Server["Server runtime"]
        Engine["engine implementation"]
        Provider["LLM provider adapter + API key"]
        History["optional history store"]
      end
    
      Connector --> Engine
      Engine --> Provider
      Engine -. optional .-> History
    ```
    
2.  ## Configure the engine server
    
    Keep provider configuration in server environment variables. Pick the adapter and model intentionally; stronger structured-output models can reduce healing and retries, while lower-latency models can improve responsiveness.
    
    src/server/engine.ts
    
    ```ts
    import { createEngine } from '@maelstrom-co/engine';
    import { llmPlanner } from '@maelstrom-co/planner-llm';
    import { geminiText } from '@tanstack/ai-gemini';
    
    export const engine = createEngine({
      planner: llmPlanner({
        adapter: geminiText(process.env.MAELSTROM_MODEL ?? 'gemini-2.0-flash'),
      }),
      retry: { max: 1 },
    });
    ```
    
    See [Use a custom LLM provider](https://docs.maelstrom-ai.co/0.2/guides/engine/custom-llm-providers/) for provider-specific setup.
    
3.  ## Choose the transport connector
    
    WebSocket is the most common production shape because Maelstrom turns are interactive. HTTP can work for request/response deployments. In-memory connectors are useful for tests, not browser deployments.
    
    Put the public connector URL in browser configuration and keep private provider keys on the server:
    
    src/client/connector.ts
    
    ```ts
    import { WebSocketConnector } from '@maelstrom-co/client';
    
    export const connector = new WebSocketConnector({
      url: import.meta.env.PUBLIC_MAELSTROM_WS_URL,
    });
    ```
    
4.  ## Make history durable if you enable it
    
    Conversation history is opt-in. If you enable it in production, use a durable store such as Redis, Postgres, or SQLite, and account for concurrency across server instances.
    
    > [!WARNING]
    > Caution
    > 
    > The in-memory history store is for local development and tests. It is lost on restart and does not coordinate across multiple deployed engine instances.
    
    Read [Enable conversation history](https://docs.maelstrom-ai.co/0.2/guides/engine/conversation-history/) before enabling history for real users.
    
5.  ## Add production error reporting
    
    Render connector state in the UI and report server-side engine failures to your observability stack. Keep the user-facing recovery path simple: if the connector is disconnected, disable intent submission; if processing fails, allow the user to retry the intent.
    
    ```tsx
    <m.Provider
      connector={connector}
      onError={(error) => {
        reportError(error);
      }}
    >
      <m.Chart />
    </m.Provider>
    ```
    

## Production checklist

-   [ ]  Browser bundle contains no LLM provider secrets.
-   [ ]  Engine server has provider keys injected from the deployment environment.
-   [ ]  Connector URL is environment-specific and points at the deployed runtime.
-   [ ]  UI renders connection and processing errors with retry paths.
-   [ ]  History is either disabled or backed by a durable store.
-   [ ]  Multi-instance deployments have session affinity, a distributed lock, or a per-session queue if history/concurrency matters.

## Next steps

-   [The Engine](https://docs.maelstrom-ai.co/0.2/understanding/engine/) — understand the reference implementation boundary
-   [Connectors](https://docs.maelstrom-ai.co/0.2/understanding/connectors/) — choose the transport shape
-   [Conversation history](https://docs.maelstrom-ai.co/0.2/guides/engine/conversation-history/) — configure durable context
