> For the complete documentation index, see [llms.txt](https://docs.edgetag.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgetag.io/playground/destination/infrastructure.md).

# Infrastructure

Some Destinations need a persistent state — a deduplication window, a rollup counter, a nightly file export, and a first-party API endpoint backed by a database. The **Infrastructure** tab lets you attach Cloudflare storage services to your Destination so your code can read and write them directly.

### Available services

| Service | Good for                                                    |
| ------- | ----------------------------------------------------------- |
| **D1**  | SQL database — reporting, subscriber lists, relational data |
| **KV**  | Key-value store — fast reads, session caches, deduplication |
| **R2**  | Object storage — file exports, archives, large blobs        |

Each service you add gets a **binding name** (for example `MY_DB`, `CACHE`, `EXPORTS`). Bindings are exposed as `params.infra.<BINDING_NAME>` inside every edge file and every API handler.

You can also open the Visualization tab and see exactly how your infrastructure works.

<figure><img src="https://1474399258-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZJWZKbUk0hRISkCIj2p4%2Fuploads%2FAHnuHXga22hUtVHFgr0e%2FScreenshot%202026-04-24%20at%209.51.37%E2%80%AFPM.png?alt=media&amp;token=8305bbc3-ea8a-40f9-bada-08833ce1e39e" alt=""><figcaption></figcaption></figure>

### Using bindings in code

**D1 (SQL database)**

```javascript
const row = await params.infra.MY_DB
  .prepare('SELECT * FROM subscribers WHERE email = ?')
  .bind(email)
  .first()
```

**KV (key-value store)**

```javascript
await params.infra.CACHE.put(`dedupe:${orderId}`, '1', { expirationTtl: 86400 })
const seen = await params.infra.CACHE.get(`dedupe:${orderId}`)
```

**R2 (object storage)**

```javascript
await params.infra.EXPORTS.put(
  `orders/${date}.csv`,
  csvString,
  { httpMetadata: { contentType: 'text/csv' } }
)
```

### Simulation and infrastructure

In [Simulation](/playground/destination/simulation.md), every binding is mocked in memory. D1 queries are captured but not executed, KV and R2 operations use an in-memory `Map`, and Analytics Engine writes are logged. Nothing persists between simulation runs, and no data reaches production.

{% hint style="info" %}
Add bindings from the Infrastructure tab before you reference them in code. Variables come from the [Variables](/playground/destination/variables.md) tab, not Infrastructure.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.edgetag.io/playground/destination/infrastructure.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
