# Bindings

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

New on /news: [Effect Office Hours 52 with Resonate HQ](/news).

**Goal:** connect a [Worker](/lore/workers-answer-requests-durable-objects-own-named-state) to a resource it declares, and see what it gets back.

A binding is a declared connection. On Cloudflare, it lets a Worker use a platform resource such as a bucket, a queue, or a stream. [Cloudflare bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/)
In [Alchemy](/skills/learn-alchemy), the binding is declared in the same [Effect](/lore/effect-basics) program as the resource.

## Worked example: the events cartridge writes to a stream

The events [cartridge](/lore/cartridges) sends one row per request to a Pipelines stream.
It binds the stream in two steps:

packages/events/src/basin.ts at a3f5a14861ce89913e82bea0f7ba02c83e8d4725; lines 56-57; highlighted 57. Title: Init: ask for a writer bound to the stream.

```typescript
      const saltValue = yield* salt.text;
      const writer = yield* Cloudflare.Pipelines.WriteStream(stream);
```

packages/events/src/basin.ts at a3f5a14861ce89913e82bea0f7ba02c83e8d4725; lines 75-75; highlighted none. Title: Runtime: provide the binding implementation.

```typescript
  ).pipe(Layer.provide(Cloudflare.Pipelines.WriteStreamBinding));
```

1. `Cloudflare.Pipelines.WriteStream(stream)` names the stream this code writes to. It returns a writer with a `send` method.
2. `Layer.provide(Cloudflare.Pipelines.WriteStreamBinding)` gives the [Layer](/lore/layers-make-dependencies-explicit) what it needs: it supplies the implementation that talks to the bound stream at runtime.

Alchemy documents the same two steps for queues: `WriteQueue` in the init phase, and `WriteQueueBinding` in the runtime layer. [Queue.ts](https://github.com/alchemy-run/alchemy/blob/v2.0.0-beta.85/packages/cloudflare/src/Queues/Queue.ts)

## Why a binding carries permission and configuration

Sam says a binding includes both permissions and environment variables.
A [service](/lore/services-capture-dependencies)'s configuration and permissions can be declared together before the application runs. [Happy Path 116, 37:09](https://youtu.be/YEn4A7XxgF4?t=2229) [37:33](https://youtu.be/YEn4A7XxgF4?t=2253)

He also describes deriving least-privilege policies: permissions limited to the methods an application uses. [Effect Office Hours 27, 58:16](https://youtu.be/fPSxB7ZgSJw?t=3496) [59:23](https://youtu.be/fPSxB7ZgSJw?t=3563)

## Next

Read [Queues, Pipelines, Workflows and K2 do different jobs](/lore/queues-pipelines-workflows-and-k2-do-different-jobs) to choose what to bind.
Read [Workers answer requests; Durable Objects own named state](/lore/workers-answer-requests-durable-objects-own-named-state) to choose where state lives.
Then read [cartridges](/lore/cartridges) for how a package owns its resources and bindings.

See [Happy Path 116](/lore/happy-path-116-infrastructure-as-effects-sam-goodwin) and [Effect Office Hours 27](/lore/effect-office-hours-27-alchemy-infrastructure-as-effects).

## Sources

1. [#116 Infrastructure as Effects with Sam Goodwin - YouTube](https://youtu.be/YEn4A7XxgF4?t=2229)
   Sam Goodwin. Binding explanation; used for permissions and environment configuration. Accessed 2026-10-01.

2. [Alchemy, Infrastructure as Effects | Office Hours 27 🔥 - YouTube](https://youtu.be/fPSxB7ZgSJw?t=3496)
   Sam Goodwin. Policy derivation discussion; used for least privilege from application methods. Accessed 2026-10-01.

3. [Bindings (env)](https://developers.cloudflare.com/workers/runtime-apis/bindings/)
   Cloudflare. Bindings let a Worker interact with resources on the Cloudflare Developer Platform. Accessed 2026-11-08.

4. [Alchemy Queue resource at v2.0.0-beta.85](https://github.com/alchemy-run/alchemy/blob/v2.0.0-beta.85/packages/cloudflare/src/Queues/Queue.ts)
   GitHub alchemy-run/alchemy. Use WriteQueue in the init phase and provide WriteQueueBinding in the runtime layer. Accessed 2026-11-08.

5. [Basin event sink](https://github.com/joelhooks/rat-stack/blob/a3f5a14861ce89913e82bea0f7ba02c83e8d4725/packages/events/src/basin.ts)
   GitHub joelhooks/rat-stack. The events cartridge binds its Pipelines stream with WriteStream and WriteStreamBinding. Accessed 2026-11-08.

## Lore on this page

- [Workers answer requests; Durable Objects own named state](/lore/workers-answer-requests-durable-objects-own-named-state)

## Linked from

- A cartridge owns one job and its resources → A cartridge owns one job and brings the infrastructure its service needs. → [Read page](https://ratstack.sh/lore/cartridges)

- Agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms.txt)

- Analytics → One event per HTTP request, stored unchanged for queries to select and interpret later. → [Read page](https://ratstack.sh/systems/analytics)

- AT Protocol separates identity, data, and application schemas → AT Protocol connects persistent account identifiers, signed public repositories, hosting services, and shared schemas. → [Read page](https://ratstack.sh/lore/at-protocol)

- Auth → Email and password sign-in through Better Auth, with the signed-in person provided to each RPC call. → [Read page](https://ratstack.sh/systems/auth)

- Change log → What changed in the files served here, newest first. → [Read page](https://ratstack.sh/log)

- Effect + Alchemy peer patterns → Source-grounded patterns from repos on nearby Effect and Alchemy pins. → [Read page](https://ratstack.sh/resources/same-version-repos)

- Effect Office Hours 27: Alchemy, infrastructure as effects → Sam Goodwin presents Alchemy as a system built with Effect for planning, testing, and deploying infrastructure. → [Read page](https://ratstack.sh/lore/effect-office-hours-27-alchemy-infrastructure-as-effects)

- Feature flags → Typed feature flags with owners, removal dates, and stable subject rollouts. → [Read page](https://ratstack.sh/systems/flags)

- Full agent guide → An Effect stack so pure (aspirational) Kit Langton will blush. → [Read page](https://ratstack.sh/llms-full.txt)

- Infrastructure as effects → Sam Goodwin relates application operations to infrastructure requirements in one typed program. → [Read page](https://ratstack.sh/lore/infrastructure-as-effects)

- Learn mode presents concepts at useful depths → An agent presents source-derived concepts during real work and keeps learning events in a private local log. → [Read page](https://ratstack.sh/systems/learn)

- learn-alchemy → Learn how Alchemy 2 turns an Effect program into a planned Cloudflare deployment. → [Read page](https://ratstack.sh/skills/learn-alchemy)

- Lint and type escape ledger (debt.md) → A source-linked count of repo-owned lint and type escapes. → [Read page](https://ratstack.sh/debt.md)

- onboard-a-list → Analyze or migrate an email list. Measure sanitation rules, preserve stops, choose a cohort, and verify an authorized import or sending cutover. → [Read page](https://ratstack.sh/skills/onboard-a-list)

- Oxlint rule limits → How the current lint rules draw their syntax boundaries. → [Read page](https://ratstack.sh/resources/lint-rule-limits)

- Purpose and boundaries of rat-stack (VISION.md) → What this starter is for and what a useful copy should keep. → [Read page](https://ratstack.sh/VISION.md)

- Queues, Pipelines, Workflows and K2 do different jobs → Pick a Cloudflare product for work outside a request by the unit you track: a message, a row, a step, or a record in a log. → [Read page](https://ratstack.sh/lore/queues-pipelines-workflows-and-k2-do-different-jobs)

- Rat Stack lore | rat-stack → Short, source-grounded notes on the ideas and decisions behind rat-stack. → [Read page](https://ratstack.sh/lore)

- Sam Goodwin on Alchemy → Sam Goodwin explains Alchemy's Effect model, plans, bindings, and cloud-library idea. → [Read page](https://ratstack.sh/lore/devtools-fm-sam-goodwin-alchemy)

- Schema projections: 2026-09-18 history → Historical Effect rc.115 proposal and implementation receipts from 2026-09-18; use the one-capability-every-surface lore page for the current pattern. → [Read page](https://ratstack.sh/resources/schema-projections-and-code-mode)

- security-audit → Security guidance and vulnerability review for codebases, APIs, services, CLI tools, libraries, and daemons. Use for security questions, focused reviews, vulnerability research, security audits, or pen tests. Run the complete workflow only for explicit codebase audit or pen-test requests, full/comprehensive/end-to-end reviews, or requested report artifacts. → [Read page](https://ratstack.sh/skills/security-audit)

- Source change history (log.md) → The generated change log as Markdown. → [Read page](https://ratstack.sh/log.md)

- Trace operations where they mean something → Name useful operations, add safe context, and distinguish creating a span from delivering it to a backend. → [Read page](https://ratstack.sh/lore/trace-meaningful-operations)

- uncomplect → Find responsibilities that a rat-stack design combines, separate them into capabilities, cartridges, machines, features, and clients, and enforce that separation through types and checks. Use when asked to simplify, review, or replace a design, "what would Rich Hickey do", "optimize for deletion", or "define this error out of existence". → [Read page](https://ratstack.sh/skills/uncomplect)

- Worker init runs twice → Alchemy Worker initialization runs in deploy and runtime contexts, so resource declarations need a boundary. → [Read page](https://ratstack.sh/lore/init-runs-twice)

## Unlinked mentions

- [A cartridge owns one job and its resources](https://ratstack.sh/lore/cartridges) → Sam describes test or development Layers for infrastructure and a type error when code still requires a removed binding.

- [Build and run rat-stack (README.md)](https://ratstack.sh/README.md) → ts also composes Website and the WEBSITE binding.

- [Effect + Alchemy peer patterns](https://ratstack.sh/resources/same-version-repos) → D1 uses a runtime Worker binding and a separate deploy-time migration connection; Hyperdrive accepts the origin URL for migrations because its runtime connection is minted per invocation, and the integration scopes auth/database work to that execution.

- [Infrastructure as effects](https://ratstack.sh/lore/infrastructure-as-effects) → What the program checks: Relationships before deployment; code that requires a removed binding¶

- [learn-alchemy](https://ratstack.sh/skills/learn-alchemy) → Binding is a typed runtime value attached to a Worker.

- [Lint and type escape ledger (debt.md)](https://ratstack.sh/debt.md) → Reason: Alchemy types the test Worker environment as a dictionary, so the binding needs one boundary cast.

- [Oxlint rule limits](https://ratstack.sh/resources/lint-rule-limits) → Residual limit and why: Mutation behind const, static fields, imported shared state, and block-scoped bindings that escape through closures are not binding-level let/var findings.

- [Purpose and boundaries of rat-stack (VISION.md)](https://ratstack.sh/VISION.md) → ts deploys nothing, and removing a binding is a type error.

- [uncomplect](https://ratstack.sh/skills/uncomplect) → Look for a database or queue declared separately from the Layer that consumes its binding.¶
