> 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="/files/hZSOXFTV1G4uZ96OeIiP" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
