---
title: "Sequentially Chunked AttributeMap"
description: "Use this pattern for append-only data that must retain insertion order, such as agent messages, subscriber history, or audit events."
canonical_url: "https://docs.superdurable.io/design-patterns/data-storage/sequentially-chunked-attribute-map/"
source: "docs/content/design-patterns/data-storage/sequentially-chunked-attribute-map.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Sequentially Chunked AttributeMap

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/design-patterns/data-storage/sequentially-chunked-attribute-map.go.md) · [Java](https://docs.superdurable.io/design-patterns/data-storage/sequentially-chunked-attribute-map.java.md) · [TypeScript](https://docs.superdurable.io/design-patterns/data-storage/sequentially-chunked-attribute-map.typescript.md) · [Rust](https://docs.superdurable.io/design-patterns/data-storage/sequentially-chunked-attribute-map.rust.md)

Use this pattern for append-only data that must retain insertion order, such as agent messages, subscriber history, or audit events.

If you keep this data in a single Attribute, the value keeps growing. Every append then reads and rewrites the whole value. A sequentially chunked **AttributeMap** splits the data into chunks, so an append rewrites only one chunk of bounded size. The sample stores at most 100 subscribers in one instance.

## Data layout

`ChunkedSubscriberFlow` is an RPC-only Flow. Start it once with no Flow timeout.

- `SubscriberArchiveState` stores the next sequence and the newest archived chunk token.
- `SubscriberChunks[current]` is the only mutable chunk.
- A full chunk moves to an immutable instance named by its zero-padded first sequence, such as **00000000000000000101**.

`RegisterSubscriber` locks the state and the **current** instance. Most calls rewrite only **current**. When **current** already holds 100 records, the same RPC call writes the archived chunk, starts a new **current** chunk, and advances the state. These writes take effect together.

Concurrent appends can receive a lock-conflict error. Retry after it; see [RPC lock conflicts](https://docs.superdurable.io/reference/server/runtime-data.md#rpc-lock-conflicts). To coordinate writes across the whole map, see [whole-map coordination](https://docs.superdurable.io/reference/server/runtime-data.md#whole-map-coordination).

`GetSubscriberPage` starts at **current** unless the caller supplies a page token. The HTTP controller uses **RPCInvokeOptions** to load only that instance. Each page returns its records newest first, plus the token of the next older page.

**Python**

```python
page = await app_state.client.invoke_rpc(
    flow.get_subscriber_page,
    FLOW_ID,
    GetSubscriberPageInput(page_token),
    options=RPCInvokeOptions(
        load_attribute_map_instances=(flow.subscriber_chunks.load(page_token),)
    ),
)
```

Example: [examples/python/dex_examples/patterns/sequentially-chunked-attribute-map/controller.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/patterns/sequentially-chunked-attribute-map/controller.py)

## Pagination rules

A page token is **current** or the 20-digit name of an archived chunk; see [Chunk page tokens](https://docs.superdurable.io/reference/server/runtime-data.md#chunk-page-tokens) for the validation rules.

Archived chunks are immutable, so a page read again, such as on a retry, returns the same records while its chunk is retained. To update older records, use a different pattern or a separate index.

For an append-only history, archive bounded chunks and load only the requested page. Bound the total as well, or storage keeps growing. Choose a limit by chunk count or age. Archive the full chunk, delete the chunks past the limit by key, and record the oldest retained token in one commit. When the business must keep old records, archive those chunks outside the Flow before you delete them. Size limits per value and per Flow are in the [Server configuration reference](https://docs.superdurable.io/reference/server/configuration.md#limits). Retained pages are immutable. At the oldest retained chunk, return no older token. A request for a pruned token returns a page-not-found result.

Many concurrent appends contend on **current**. When they would conflict often, route them through an RPC that publishes each record to a Channel. One writing Step consumes it and appends, as in the [Idle Timer with Resolution](https://docs.superdurable.io/design-patterns/external-interaction/idle-timer-with-resolution.md).

## HTTP API

```text
POST /patterns/sequentially-chunked-attribute-map/start
POST /patterns/sequentially-chunked-attribute-map/register
GET  /patterns/sequentially-chunked-attribute-map/subscribers?pageToken=current
```

The chunk size is part of the stored layout. A later version of the application can use a new chunk size for new archives. Its page-token logic must then read both layouts.

## Next

[Hash-Partitioned AttributeMap](https://docs.superdurable.io/design-patterns/data-storage/hash-partitioned-attribute-map.md)
