# Pub/Sub pricing How Pub/Sub operations contribute to your message count and strategies to optimize costs. Pub/Sub operations contribute to your message count based on publishing, delivery, and optional features like persistence and presence. ## Pub/Sub operations The following table shows how Pub/Sub operations contribute to your message count: | Operation | Messages counted | | --- | --- | | [Messages](https://ably.com/docs/channels/messages.md) || | Publish | 1 inbound message | | Message delivery | 1 outbound message per subscriber | | [Presence](https://ably.com/docs/presence-occupancy/presence.md) || | Presence enter | 1 inbound message | | Presence leave | 1 inbound message | | Presence update | 1 inbound message | | Presence event delivery | 1 outbound message per presence subscriber | | Presence REST query | 1 outbound message per member returned | | Batch presence request | 1 outbound message per member across all queried channels | | [Storage and history](https://ably.com/docs/storage-history/storage.md) || | Persistence storage | 1 additional message per stored message | | History retrieval | 1 outbound message per retrieved message | | [Rewind](https://ably.com/docs/channels/options/rewind.md) on attach | 1 outbound message per rewound message (up to 100) | | [Integrations](https://ably.com/docs/platform/integrations.md) || | Integration delivery | 1 outbound message per integration target | | [Inbound integration publish](https://ably.com/docs/platform/integrations.md#inbound) | 1 inbound message | | [Push notifications](https://ably.com/docs/push.md) || | Push notification delivery | 1 outbound message per delivered notification | | [Annotations](https://ably.com/docs/messages/annotations.md) || | Annotation publish | 1 inbound message | | Annotation delete | 1 inbound message | | [Annotation summary delivery](https://ably.com/docs/messages/annotations.md#annotation-summaries) | 1 outbound message per subscriber; multiple annotations may be rolled up into a single summary | | [Metadata and stats](https://ably.com/docs/metadata-stats/metadata.md) || | Lifecycle event (`[meta]connection.lifecycle`, `[meta]channel.lifecycle`) | 1 outbound message per event | | `[meta]stats:minute` event | 1 outbound message per event | | `[meta]log` subscription | Not counted | ## Channels [Channels](https://ably.com/docs/channels.md) are the unit of message distribution. Each channel you use contributes to your [channel count](https://ably.com/docs/platform/pricing.md#channels). Ably includes channels with each package and charges for additional channels beyond the included allowance. ## Connections Ably bills each connected client for [connection minutes](https://ably.com/docs/platform/pricing.md#connections). A connection-minute is counted for every minute a client maintains an open connection, regardless of activity. Clients that remain connected but idle still accrue connection minutes. ## Cost optimization ### Use ephemeral messages Mark messages as [ephemeral](https://ably.com/docs/pub-sub/advanced.md#ephemeral) to exempt them from persistence, rewind, resume, and integrations. Use this for streaming data where history is not needed. ### Disable self-delivery Set [echoMessages: false](https://ably.com/docs/pub-sub/advanced.md#echo) to prevent messages from being delivered back to the publisher. This is useful for optimistic UI patterns and server-side publishers. ### Enable conflation [Conflation](https://ably.com/docs/guides/pub-sub/data-streaming.md#solution-message-conflation) delivers only the latest message per key in each time window. Use this for high-frequency updates where only the latest value matters. ### Use server-side batching [Server-side batching](https://ably.com/docs/guides/pub-sub/data-streaming.md#solution-server-side-batching) groups messages into single deliveries. Use this for high-throughput channels where slight delay is acceptable. ### Enable delta compression [Delta compression](https://ably.com/docs/channels/options/deltas.md) reduces payload size, lowering bandwidth costs. Use this for large, structurally similar successive messages. ### Use occupancy instead of presence Use [occupancy](https://ably.com/docs/presence-occupancy/occupancy.md) instead of presence when you only need member counts, not individual identities. This avoids the n-squared presence event fan-out where each member event is delivered to every subscriber. For example, 200 members joining and leaving a channel generates approximately **80,400 messages**. See [large-scale presence sets](https://ably.com/docs/presence-occupancy/presence.md#large-presence) for the full calculation. ### Enable server-side presence batching Enable [server-side batching](https://ably.com/docs/presence-occupancy/presence.md#large-presence) to group presence events and support up to 20,000 members per channel. Subscribe to presence updates only on channels where you need member-level detail. ## Documentation Index To discover additional Ably documentation: 1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages. 2. Identify relevant URLs from that index. 3. Fetch target pages as needed. Avoid using assumed or outdated documentation paths.