# Limits

URL: https://docs.folkways.io/docs/realtime-api/limits

Protocol limits, rate limits, retention and naming rules of the Realtime API, with their defaults.

Clients learn the limits in force when they connect, in `Welcome.limits`. Read them from there rather than
hard-coding them. For what Folkways doesn't do at all, see [Current limitations](/docs/concepts/limitations).

## Protocol [#protocol]

| Limit | Default | Meaning |
| --- | --- | --- |
| `max_frame_bytes` | 65,536 | Largest packet you may send: a WebSocket message or HTTP body |
| `max_payload_bytes` | 61,440 | Largest payload, on every package; lower if the segment or rule sets it |
| `max_frames_per_packet` | 64 | Frames per packet |
| `max_subscriptions` | 1,000 | Subscriptions per connection |
| `max_topic_bytes` | 255 | Longest topic name |
| `max_headers` | 16 | Headers per event |
| `heartbeat_ms` | 30,000 | How often to ping |
| `idle_timeout_ms` | 90,000 | Silence before the connection is closed |

## Names [#names]

| Item | Rule |
| --- | --- |
| Topic name | ASCII levels separated by `/`, each of `A-Z a-z 0-9 . _ ~ : @ = + -`; at most 16 levels and 255 bytes. `$` names are reserved |
| Event name | 1–64 bytes of UTF-8 |
| Identity (`sub`) | At most 256 bytes; not starting with `anon:`. One topic level for personal topics and presence |
| Device label | At most 64 bytes |

## Retention and state [#retention-and-state]

| Item | Default |
| --- | --- |
| Stream history per topic | 5 MiB (the rule's retention), at most 24 hours |
| KV value lifetime | Until replaced or deleted, unless a TTL is set |
| Signal lifetime | 5 seconds |
| KV values and signals per topic | 10,000 |
| Idempotency window | 10 minutes, 10,000 keys per topic |
| Personal topic history | 256 KiB per user, at most 24 hours |
| Presence status data | 1,024 bytes of JSON |
| Members per private topic | 10,000; 1,000 per request |
| DM members | 2 to 50 |
| Token lifetime | 15 minutes at most |
| Long-poll wait | 25 seconds at most; 100 events by default, 1,000 at most |

## Rate limits [#rate-limits]

Rate limits come from the segment's [rate preset](/docs/console/segments#rate-preset), scaled by the connections your
package allows, and lowered by any overrides. They are announced in `Welcome.limits`; a value of 0 means not
announced, so rely on `RateLimited` and `Flow` instead.

| Limit | Meaning |
| --- | --- |
| `publish_per_sec`, `publish_burst` | Publishes per second from one connection, and the burst above it |
| `topic_publish_per_sec`, `topic_publish_burst` | Publishes per second into one topic, from everyone |
| `segment_publish_per_sec`, `segment_publish_burst` | Publishes per second across the segment |
| `inbound_bytes_per_sec`, `outbound_bytes_per_sec` | Bytes per second into and out of the segment |
| `max_subscribers_per_topic` | Subscribers one topic holds at once |
| `subscribes_per_min`, `topic_creates_per_min`, `new_connections_per_min` | Per minute, across the segment |

Over a rate limit, the request gets `RateLimited` with `retry_after_ms` and nothing is published; the connection stays
open. Over the outbound limit, every event is still delivered and publishers are slowed with
[`Flow`](/docs/realtime-api/subscribe#flow-control).

Backend endpoints (DMs, members, kick, revoke) share a per-segment budget: one unit per request (per member for DMs),
refilling at the segment's per-connection publish rate and holding up to 64.

## Package allowances [#package-allowances]

Connections, monthly messages, monthly data transfer, topics and segments are set by your package. See
[Usage and limits](/docs/console/usage).
