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

# Writing a Sink

> The Sink interface and how to implement it.

A sink implements `Sink`, defined in the repo's root `sink.go`:

```go theme={"theme":"vitesse-black"}
type Sink interface {
	Spec() SinkSpec
	Open(ctx context.Context, run RunSpec) error
	Apply(ctx context.Context, b Batch, opts ApplyOptions) (WriteReceipt, error)
	Commit(ctx context.Context) error
	Abort(ctx context.Context) error
	Name() string
}
```

* **`Spec`** is the sink's self-description — identity, config schema, and
  capabilities (what powers the catalog, same as a source's `Spec`).
* **`Open`** prepares the sink for one run.
* **`Apply`** writes a `Batch` under an `ApplyOptions.Policy` (the write
  policy governing that batch), returning a `WriteReceipt`.
* **`Commit`** or **`Abort`** finalizes the run.

`SinkSpec.SchemaField` names the pipeline-scoped config field that holds
where output lands — a schema, namespace, database, or key prefix — so the
server can default it from the source connection's normalized name.

## Optional capabilities

A sink can implement staged/transactional writes, key-based upserts, or
typed DDL (materializing a resource's schema ahead of its records). See
[Optional interfaces](/pages/connectors/building-a-connector/optional-interfaces).

## Registering it

Same pattern as a source: a `register.go` that registers with the engine,
then a blank import wherever it should be available — see [Embedding as a
library](/pages/guides/deployment/embedding-as-a-library).
