Sub topic 13
Allocations and limits
This chapter assumes you can read a change event, write an Apex trigger on one, and subscribe from empApi or an external client. It covers the limits that decide whether a CDC design keeps working under production load.
Three kinds of limits
CDC limits fall into three groups: how many objects you can track, how many events you can receive, and how long events stay available.
| Limit type | What it controls | Where it applies |
|---|---|---|
| Selected entities | How many objects can have CDC enabled | Setup, per org |
| Event delivery allocation | Events sent to CometD and Pub/Sub API clients per 24 hours | External and LWC subscribers |
| Retention window | How long events can be replayed | Event bus, 72 hours |
The exact numbers depend on your edition and on any add-on licenses. Treat figures from older blog posts as stale. Check the current Platform Events and Change Data Capture developer guides, and read your own org's values from the Limits API.
Selected entities
Each object you select on the Change Data Capture page in Setup counts against an entity limit. Without the Change Data Capture add-on license, the limit is small. Some editions allow only about five objects, and the add-on raises it. Enabling an object fails once you reach the cap. Pick objects that have a real consumer, and don't enable everything to be safe.
Delivery allocation
The delivery allocation is a rolling 24-hour count of events sent to CometD and Pub/Sub API clients. An LWC using empApi counts, because it uses CometD. The count is per event per client, so three subscribers on one event use three deliveries.
Apex triggers on change events do not count against this allocation. Moving work from an external subscriber to a trigger can therefore save allocation. Triggers still obey normal Apex governor limits.
Your org also limits the number of concurrent CometD clients. Many open browser tabs, each running a component that subscribes, can use this up faster than expected.
Checking your usage
The Limits REST resource reports the remaining allocation. Run this with a valid session token:
curl -s "$INSTANCE_URL/services/data/v60.0/limits" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
| grep -A 3 "DailyDeliveredPlatformEvents"The response gives Max and Remaining values. Poll them from a monitoring job and alert when Remaining drops below a threshold.
What happens at the limit
When a CometD or Pub/Sub client exhausts its allocation, Salesforce stops delivering events to it. Events are still published to the bus and stay replayable. A client that recovers within the retention window can reconnect with its last stored replay ID and receive what it missed. If the outage lasts longer than 72 hours, the events are gone. You then need a full reconciliation, as in the gap and overflow chapter.
Reducing consumption
- Select only the objects you need.
- Use a custom channel with filtering so each client receives only the events it needs.
- Let one backend subscriber receive events and fan them out internally, instead of having every browser subscribe.
- Use Apex triggers when the work stays inside Salesforce.
- Use Pub/Sub API flow control: request only as many events as the client can process.
Exercise
An LWC on a busy home page subscribes to /data/AccountChangeEvent, and 400 users keep it open. Why can this drain the delivery allocation, and what is a better design?
Show answer
Each user's CometD client receives its own copy of every event, so each change is counted once per open subscription. A better design has one backend subscriber, or an Apex trigger, process the events once and update a record or publish a smaller custom event. Users then read that result, or a filtered custom channel limits who receives what.