OBLYTECH Logo
OBLYTECH Logo

Moving From Streaming API to Pub/Sub API for Event Subscriptions

The Pub/Sub API is the interface to build new Salesforce event subscriptions on, and the Streaming API is the one many existing integrations still run on. Moving between them is mainly planning: inventory each subscription, assign an owner to each event flow, run the replacement beside the old feed, and switch consumers one at a time.

Why the Pub/Sub API is the default for new publish-subscribe work

When a team designs a new subscriber today, the real question is which interface to build against. For new work, the Pub/Sub API is the route to design around. The Streaming API stays in place for existing consumers, and the migration plan should aim to retire it once they have moved.

The transport is the main design difference. The Streaming API uses the CometD protocol, with the client holding a long-polling connection and handling subscriptions and reconnects through a library. The Pub/Sub API uses gRPC over HTTP/2 and encodes payloads with Avro, so each subscriber works against a typed event schema and requests events in explicit batches. Confirm that a client library for your language supports the current Pub/Sub API before committing to a design, because library releases move on their own timetable.

How the two interfaces differ in the parts that change a migration

Several differences matter more than others for planning. Four of them change the work, and each one should be checked against the subscriptions in your inventory before the first line of new code is written.

  • Message encoding. Streaming API messages arrive as JSON. Pub/Sub API payloads are Avro-encoded, so the subscriber needs the event schema to decode them and a step that resolves the schema identifier carried with each event.
  • Resume logic. Both interfaces can replay from a stored replay ID, but the request is made differently. Replay code should be rewritten rather than ported line by line, since porting it is a common source of silent gaps.
  • Supported event sources. Confirm which event types each interface supports on your release. A subscription that watches record changes through a query-based definition may need a different trigger on the new interface, such as a change data capture subscription or a platform event published from the same business logic.
  • Flow control. The Pub/Sub API asks for events in batches sized by the subscriber. Set the batch size with the downstream write rate in mind. A subscriber that requests more than it can write builds a backlog that is hard to see from outside.

Inventorying existing Streaming API subscriptions before any code changes

Start with a list rather than code. Record each Streaming API client that your org and its connected systems depend on, including the ones set up for a single report or dashboard and not touched since. Forgotten subscriptions are common, and they tend to surface after cutover, when a downstream number stops updating.

For each subscription, record:

  • The channel or event definition it subscribes to, and the object or event type behind it.
  • The system that consumes the messages and the team that owns that system.
  • Whether the client stores replay IDs and where they are kept.
  • The downstream action, such as writing to another system, sending a notification or updating a record.
  • The expected message volume at normal and peak load.

A subscriber that handles a few events an hour can tolerate a slow, careful cutover. One that feeds a live queue needs its parallel run to cover a peak period, and it needs enough headroom in the org’s limits to run two subscribers at once. Use the integration architect checklist for API call budgets to size that headroom before the parallel run starts.

Deciding which system owns each event flow before moving it

Some subscriptions exist because one platform reacts to another. An event published in Salesforce that opens a record, changes a status or starts a task in a second platform is part of a boundary, not just a subscription. Before moving it, confirm which side owns the event and which side owns the resulting action. A migration is a good point to remove a duplicate path, where two systems both react to the same change, instead of carrying both over to the new interface.

Where a subscription crosses between Salesforce and ServiceNow, check the ownership split against the integration boundaries page for Salesforce and ServiceNow before cutover.

Designing a parallel run that keeps event delivery intact

The safest route is a parallel run. The existing Streaming API subscriber keeps writing to production while a new Pub/Sub subscriber consumes the same event types into a staging target. Compare the two outputs over a full business cycle, including month-end closes and batch imports. A run shorter than one full cycle can miss the failures that surface at period end.

Two things should be ready before the run starts. The first is idempotent writes in the new subscriber. A reconnect can redeliver events that were already processed, so writes should key on a stable business identifier from the payload, or on the replay ID, and a duplicate should update the existing row rather than create another. The second is a durable store for the last processed replay ID, read on startup, so a restart resumes from the right point.

Backfill is the third thing to plan. If the new subscriber starts from the latest event, anything published during the gap does not reach the new target, so decide up front whether the window needs a backfill and how it will be loaded. Treat the backfill as a bulk migration with its own checks, and follow the data migration integration guidance for the load itself.

Steps for the parallel run

  1. Build the new subscriber against a non-production org that has the same event types enabled, and confirm that a sample payload decodes into your target model without manual edits.
  2. Point the new subscriber at the production event feed in read-only mode, writing to a staging table rather than the live target.
  3. Compare daily record counts and a sample of field values between the staging output and the existing pipeline. Apply the data quality migration checks to both sides before comparing, so that a formatting difference is not mistaken for a missed event.
  4. When a mismatch appears, trace it to its source and fix the cause, then restart the comparison from the beginning of the period. Restarting from the point of the fix hides the gap that caused the problem.
  5. Switch the live write to the new subscriber once the comparison has been clean for a full cycle. Leave the old subscriber paused rather than deleted, so a rollback is a configuration change and not a rebuild.

Cutover order, rollback and retirement

Cut over one subscription at a time, beginning with the one that carries the least business risk. Each cutover should have a named owner on the consuming side who can confirm that downstream data looks right, and a recorded date after which the old subscriber is removed. Batching several cutovers into one change makes it hard to tell which change caused a problem.

Rollback is simplest while the old client is still deployed. Keep its configuration in source control and record the replay ID it last processed, so it can resume from that point if the new subscriber has to be turned off. Events published during the gap can be recovered while they stay inside the replay window on your org, so run the rollback check while that window is still open rather than after the fact.

Retire a Streaming API subscription once its consumer has run cleanly on the new interface through a full business cycle. Then remove the definition on the Salesforce side, the client, and any credentials that client alone used. Update the inventory in the same change, so the next person does not rebuild something that already moved.

For help planning this work, see Salesforce implementation.

Questions about moving existing Streaming API subscriptions

Can one codebase serve both interfaces during the transition?

Often yes, and it is the lowest-risk option when several consumers depend on the same event. Put a thin adapter in front of the business logic. Each interface’s subscriber converts its payload into one internal message type, and the downstream code reads that type alone. Once the old subscriber is retired, the adapter can be removed without touching the business code.

How do I tell whether events are missing or being processed twice?

Compare two numbers over the same window: the count of events received by the subscriber and the count of distinct business keys written downstream. If the received count is higher and the difference is explained by duplicate keys, the cause is redelivery and the idempotent write logic needs attention. If the received count is lower than an independent count of changes in the source system for the same period, events are being missed, often because a replay went wrong after a reconnect.

Who should sign off on a cutover?

Two roles should sign off: the owner of the downstream data, who confirms the numbers and records look right, and the owner of the integration, who confirms the subscriber is healthy and the rollback path is ready. One person doing both tends to skip the comparison step, which is the step that catches the problems.

Does a PushTopic need a direct replacement?

Not necessarily. A PushTopic watches a query for record changes, and that behavior does not translate one to one into the Pub/Sub API. The usual replacement is a change data capture subscription for the object when the requirement is record change notification, or a platform event published from the same logic that updates the record when the consumer needs a specific message. Settle which one fits the consumer’s real need before writing code.