> This page is part of EVVA for Developers (https://developers.evvahub.com), the documentation of the EVVA Partner API. The API is in developer preview and the SDK packages are not yet published: do not suggest installing them. Index: https://developers.evvahub.com/llms.txt

# Event feed and consumer groups

The event feed is the durable record behind [realtime](/realtime) and [webhooks](/webhooks/overview): the same events,
with the same `eventId`, kept for **7 days**. Poll it with a cursor; nothing is lost while you are away.

## Read the feed

[`GET /partner/v1/events`](https://developers.evvahub.com/api-reference/events/list-events) answers a page of events after a cursor.

| Parameter | Meaning                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `after`   | Optional, opaque cursor — an item's `cursor`, a page's `nextCursor`, or a consumer-group lease's `cursor`. Omit it to start at the oldest retained event. |
| `limit`   | 1 to 1000 items, default 100.                                                                                                                             |

**`cURL`**

```bash title="cURL"
curl -sS "https://api.evvahub.com/partner/v1/events?limit=100&after=$CURSOR" \
  -H "Authorization: Bearer $TOKEN"
```

**`TypeScript`**

```typescript title="TypeScript"
const consumer = evva.feedConsumer({
  consumerId: 'crm-sync',
  handler: async (event) => {
    await saveToCrm(event);
  },
});
await consumer.drain(); // catch up once and return (cron, replay); start() keeps polling
```

**`Python`**

```python title="Python"
from evva_partner import FeedConsumer, SQLiteStore, stop_on_signals

store = SQLiteStore("/var/lib/my-app/evva.db", namespace="crm-sync")
consumer = FeedConsumer(client, consumer_id="crm-sync", handler=handle, checkpoints=store, dedup=store,
                        on_cursor_expired=resync_from_rest)
stop_on_signals(consumer)   # finish the in-flight event, save, return
consumer.run()
```

**`PHP`**

```php title="PHP"
$consumer = $evva->feedConsumer('crm-sync', function (PartnerEvent $event, EventContext $ctx) { /* … */ },
    checkpointStore: new PdoCheckpointStore($pdo), dedupStore: new PdoDedupStore($pdo));
$consumer->drain();   // catch up once; run() keeps polling
```

**`200 OK`**

```json title="200 OK"
{
  "items": [
    {
      "eventId": "evt_01EXAMPLE",
      "type": "message.received",
      "schemaVersion": 1,
      "occurredAt": "2026-12-01T10:00:00.000Z",
      "publishedAt": "2026-12-01T10:00:00.120Z",
      "applicationId": "app_EXAMPLE",
      "agencyId": "agency_EXAMPLE",
      "creatorId": "creator_EXAMPLE",
      "conversationId": "conversation_EXAMPLE",
      "correlationId": null,
      "cursor": "opaque-cursor-1",
      "data": { "messageId": "message_EXAMPLE", "senderRole": "USER", "buyerRef": "buyer_EXAMPLE" }
    }
  ],
  "nextCursor": "opaque-cursor-2",
  "hasMore": false
}
```

### How to read it

* **Save a cursor after you handle an event, not before.** Every item carries its own `cursor`, so you can checkpoint
  mid-page; `nextCursor` is always present and safe to resume from once the whole page is handled.
* **`hasMore: true` with fewer than `limit` items is normal.** One call examines a bounded number of rows; ask again.
* **Deduplicate on `eventId`.** Delivery is at least once; a crash between handling and saving re-delivers.
* **The order is deterministic.** Reading again from the same cursor, replaying from the start or resuming a consumer
  group after a takeover returns the same events in the same order. Within a creator the order never changes; across
  creators no order is promised.
* **Never order by `occurredAt`.** It is informational, not the delivery order, and two events can share an instant.
* **Cursors are opaque.** A cursor is encrypted and works only for your application, in its agency and environment. It
  shows neither its position nor whether it moved, and two cursors for the same position differ, so never compare
  them. Events carry no `sequence`.
* **Visibility is decided when you read.** Each event is shown only if your grants, the creator's consent and your
  token cover its type's scopes at that moment. An event hidden when its page is read is still passed by the cursor:
  granting access later does not replay history into the feed — use the REST reads for history.

### When a cursor stops working

| Answer                 | Meaning                                                                                             | What to do                                                                              |
| ---------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `410 CURSOR_EXPIRED`   | Your cursor points before the 7-day retention.                                                      | Resynchronise what you depend on through the REST API, then read again without `after`. |
| `400 INVALID_CURSOR`   | Malformed, tampered with, issued to another application, or a webhook's `whc1.` correlation cursor. | Use a cursor this feed gave you.                                                        |
| `503 FEED_UNAVAILABLE` | The feed is not available on this deployment right now.                                             | Retry after `Retry-After`.                                                              |

## Consumer groups

When several instances of your application read the feed, a **consumer group** splits the work and keeps one shared
position. Events are spread over **16 partitions** by creator, so each creator's events stay in order inside one
partition. A group is identified by your application and a name you choose (`consumer`).

```mermaid
sequenceDiagram
    autonumber
    participant A as Instance A
    participant B as Instance B
    participant EVVA as EVVA feed
    A->>EVVA: GET /events/checkpoints?consumer=crm&partitions=0,…,7
    EVVA-->>A: lease {cursor, fencingToken, leaseExpiresAt, partitions 0–7}
    B->>EVVA: GET /events/checkpoints?consumer=crm&partitions=8,…,15
    EVVA-->>B: lease {cursor, fencingToken, partitions 8–15}
    A->>EVVA: GET /events?after=<A's lease cursor>
    EVVA-->>A: events of partitions 0–7
    A->>EVVA: POST /events/checkpoints {consumer, cursor, fencingToken}
    EVVA-->>A: committed, lease renewed
    Note over A,EVVA: A stops renewing — its lease expires
    B->>EVVA: GET /events/checkpoints?consumer=crm&partitions=0,…,7
    EVVA-->>B: lease taken over (new, higher fencing token)
    A->>EVVA: POST /events/checkpoints with the old token
    EVVA-->>A: 409 STALE_FENCING_TOKEN
```

#### Lease partitions

[`GET /partner/v1/events/checkpoints`](https://developers.evvahub.com/api-reference/events/get-event-checkpoint) with `consumer` and, optionally,
`partitions` (all 16 when omitted). You get a lease — `cursor`, `fencingToken`, `leaseExpiresAt`, `partitions` —
when no other member holds a live lease on any of them; otherwise `409 LEASE_HELD` with `Retry-After`.

#### Read with the lease's cursor

Pass the lease's `cursor` as `after`. It covers exactly your partitions. A partition never committed starts at
the oldest retained event.

#### Commit and renew

[`POST /partner/v1/events/checkpoints`](https://developers.evvahub.com/api-reference/events/commit-event-checkpoint) with `consumer`, the `cursor` you
reached and your `fencingToken`. That records the position and renews the lease. To renew without committing,
call the `GET` again with your `fencingToken`.

#### Renew before the lease runs out

Leases last about 30 seconds by default — read `leaseExpiresAt`. A lapsed lease can be taken over by another
member, which receives a new, higher fencing token.

| Refusal                   | Meaning                                                                                                          |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `409 LEASE_HELD`          | Another member holds a live lease on a partition you asked for. Wait `Retry-After`, or ask for other partitions. |
| `409 STALE_FENCING_TOKEN` | Your lease was taken over. Stop processing those partitions and lease again.                                     |
| `409 NOT_LEASED`          | The cursor covers a partition this group never leased.                                                           |
| `400 INVALID_CURSOR`      | The cursor was issued to another application.                                                                    |

Checkpoints hold positions only, never event data.

> **Tip**
>
> The PHP SDK's `ServerCheckpointStore` uses consumer groups directly, so several PHP workers can share one position.
> In the other SDKs, a `CheckpointStore` on your own database does the same job.

## Next steps

#### [Realtime](/realtime)

Low latency on top of the feed.

#### [Event catalogue](/webhooks/events)

Every event type and its data.

#### [Pagination and cursors](/conventions/pagination)

Cursors across the rest of the API.

#### [Webhooks](/webhooks/overview)

Have events pushed to you instead.