> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useshipd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Client vs. server evaluation

> When to evaluate flags with the browser SDK versus on your server, what each SDK exposes, how to deliver private values to a frontend, and why flags do not replace authorization.

## Overview

Use the browser SDK (`shipdit/client`) for flags whose evaluated values are safe to expose to anyone with your public client SDK key. Evaluate flags on your server (`shipdit` or the Go SDK) when targeting depends on verified identity, role, or billing plan, or when flag values should stay private. You can combine both in one app, and neither replaces backend authorization.

## What each SDK exposes

Server and browser SDKs use different credentials and receive different data from the edge.

| | Server SDK (`shipdit`, Go) | Browser SDK (`shipdit/client`, `shipdit/client/react`) |
| - | - | - |
| SDK key | `shipd_sdk_server_…` (secret, server-only) | `shipd_sdk_client_…` (public in browser bundles) |
| Where evaluation runs | Locally in process from a downloaded snapshot | At the edge (`POST /sdk/v1/evaluate`); values kept in memory |
| Snapshot access | Full environment snapshot (`GET /sdk/v1/snapshot`), including all flags, targeting rules, audiences, rollouts, and variants | None (`GET /sdk/v1/snapshot` returns `403`). Rejects `bootstrap` and snapshot `cache` adapters |
| Flag visibility | Every flag in the environment | Only explicitly requested flags with `clientAvailable: true` (default is `false`) |
| Trust in evaluation context | Verified by your server (session, RBAC, billing database) | Caller-supplied (`userId`, `attributes`, `segmentIds` can be spoofed) |
| Realtime updates | `stream: true` invalidates and refreshes the local snapshot | `stream: true` invalidates and refreshes requested values from `/sdk/v1/evaluate` |

A server snapshot contains your full targeting configuration—rules, audience predicates, rollout percentages, and every variant value. Keep server SDK keys and snapshots on infrastructure you control. Never serialize a server snapshot into browser HTML or pass it to a client.

A browser SDK never downloads a snapshot, so targeting rules, audiences, unused variants, and server-only flags (`clientAvailable: false`) stay off the user's device. However, a client SDK key is still a public credential: anyone who extracts the key from your bundle can call `POST /sdk/v1/evaluate` with any `userId`, `attributes`, or `segmentIds` they choose and read the resolved value (including any JSON payload) for every flag marked `clientAvailable: true`.

## Choose where to evaluate a flag

| Use the browser SDK (`shipdit/client`, `clientAvailable: true`) | Evaluate on the server (`shipdit` / Go, `clientAvailable: false`) |
| - | - |
| Public UI presentation rollouts (layout, editor, navigation variants) | Decisions based on verified user identity, organization membership, role, or billing plan |
| Anonymous visitor and marketing experiments | Internal tools, debug routes, or staff-only capabilities |
| Browser-only context such as edge geolocation (`country`, `region`, `city`, `timezone`) | Private beta access where you do not want callers probing who is enabled |
| Non-sensitive copy, styling, or UI config where spoofing traits has no security or business impact | Sensitive JSON payloads, operational kill switches, or backend API behavior |

Many applications use both patterns together: the browser SDK with `stream: true` drives public UI presentation flags with realtime updates, while an authenticated backend endpoint delivers private evaluated values.

## Deliver privately evaluated values to your frontend

When a frontend needs the result of a server-only flag, evaluate an explicit allowlist of flags on your backend and return only the resolved values—never the raw snapshot or targeting rules.

### 1. Evaluate allowlisted flags with verified server identity

Derive `userId`, organization membership, role, and plan from your authenticated session and database. Ignore targeting attributes sent in the request body or query string, and disable HTTP caching with `Cache-Control: no-store`.

```ts src/routes/capabilities.ts theme={null}
import { Hono } from "hono";
import { shipd } from "../lib/shipd.server";

export const capabilitiesRoute = new Hono();

capabilitiesRoute.get("/api/capabilities", async (c) => {
  const session = await requireAuthenticatedSession(c); // verifies user, org, role, plan
  const context = {
    userId: session.userId,
    attributes: {
      organizationId: session.organizationId,
      role: session.role,
      plan: session.plan,
    },
  };

  return c.json(
    {
      // Explicit allowlist of evaluated values only; never return a snapshot.
      auditLog: shipd.isEnabled("audit-log", context),
      localEvaluations: shipd.isEnabled("local-evaluations", context),
    },
    200,
    { "Cache-Control": "no-store" },
  );
});
```

In frameworks with server rendering (such as [Next.js](https://docs.useshipd.com/sdks/nextjs.md#evaluate-on-the-server)), you can evaluate the same allowlist during the server render and pass the resolved values as props to avoid an initial loading flash.

### 2. Keep private values updated in the browser

Pair initial loading with polling, and add an authenticated Server-Sent Events (SSE) invalidation stream when you want realtime updates:

1. **Initial fetch or SSR props.** Load the evaluated values after authentication completes.
2. **Polling fallback.** Refetch `/api/capabilities` periodically (for example, every 30 seconds) or on window focus.
3. **Realtime invalidations (optional).** Run your server SDK client with `stream: true`, subscribe with `shipd.subscribe(...)`, and push an empty invalidation event over an authenticated SSE route (`Cache-Control: no-store`). When the browser receives the event, it refetches `/api/capabilities`.

```ts src/routes/capabilities-stream.ts theme={null}
import { Hono } from "hono";
import { streamSSE } from "hono/streaming";
import { shipd } from "../lib/shipd.server";

export const capabilitiesStreamRoute = new Hono();

capabilitiesStreamRoute.get("/api/capabilities/stream", async (c) => {
  await requireAuthenticatedSession(c);
  c.header("X-Accel-Buffering", "no");

  const response = streamSSE(c, async (stream) => {
    let dirty = false;
    let wake: (() => void) | undefined;
    const stop = () => {
      wake?.();
      stream.abort();
    };
    const unsubscribe = shipd.subscribe(() => {
      dirty = true;
      wake?.();
    });
    // Bound stream lifetime so reconnects re-check session and membership.
    const timeout = setTimeout(stop, 30_000);
    stream.onAbort(stop);

    try {
      while (!stream.aborted) {
        if (dirty) {
          dirty = false;
          await stream.writeSSE({ event: "capabilities.updated", data: "{}" });
          continue;
        }
        await new Promise<void>((resolve) => {
          wake = resolve;
        });
        wake = undefined;
      }
    } catch {
      // Client disconnected; EventSource will reconnect and re-authenticate.
    } finally {
      clearTimeout(timeout);
      unsubscribe();
    }
  });

  // Hono's streamSSE sets Cache-Control: no-cache; override it on the response.
  c.header("Cache-Control", "no-store");
  response.headers.set("Cache-Control", "no-store");
  return response;
});
```

```ts src/lib/use-capabilities.ts theme={null}
const stream = new EventSource("/api/capabilities/stream", { withCredentials: true });
stream.addEventListener("capabilities.updated", () => {
  void refetchCapabilities();
});
```

Sending only an empty invalidation event keeps flag data out of long-lived stream buffers and forces every refetch of `/api/capabilities` to re-verify authentication, organization membership, role, and plan.

## Flags do not replace backend authorization

> [!WARNING]
>
> Never rely on a flag—client-evaluated or server-evaluated—as your only access control check.

Flags control feature rollout and UI exposure, not permissions:

* **Browser flags are untrusted.** Any user can inspect your bundle, spoof evaluation context, or call your API directly without going through hidden UI.
* **Authenticated capability endpoints only inform the UI.** Returning `{ auditLog: true }` from `/api/capabilities` tells the browser what to render; it does not protect the underlying API route.
* **Enforce authorization on every backend handler.** Check authentication, role/RBAC permissions, tenant membership, and billing entitlements on every read and mutation endpoint. If a backend feature is also behind a release flag, evaluate the server-only flag *in addition to*—never instead of—your authorization checks.

## Related

* [Browser SDK](https://docs.useshipd.com/sdks/browser.md)
* [Node.js and server runtimes](https://docs.useshipd.com/sdks/node.md)
* [Next.js](https://docs.useshipd.com/sdks/nextjs.md)
* [SDK keys, management API keys, and service account tokens](https://docs.useshipd.com/concepts/keys.md)
* [Local evaluation](https://docs.useshipd.com/concepts/local-evaluation.md)
* [Snapshots](https://docs.useshipd.com/concepts/snapshots.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.