20

Salesforce offers two variants of the Streaming API - PushTopic and Generic.

In Summer '17 (v40.0) Platform Events are now also Generally Available (GA).

How do they differ and why would you use one over the other?

1
  • 1
    This is the best read I've seen on the difference between Streaming Events (look at the chart towards the bottom of the post) Commented Feb 12, 2019 at 14:48

3 Answers 3

22

Very generally, the Streaming API was created primarily to update UI components(Source) where as Platform Events are for integrations via a Message Bus.

With a PushTopic from the Streaming API you are limited to receiving events notifications when the configured query and event occur. There is no capacity to manually generate these events beyond causing the criteria required by the query and event.

Generic Streaming via the Streaming API is similar to Push Topics but is not bound to specific changes to Salesforce data. Instead you control when to publish an event. The trade off is that the payload of the event is a 3000 character string rather than a defined structure like that of a PushTopic.

Platform Events provide the defined notification structure of a PushTopic with a more flexible model than Generic Streaming for raising and subscribing to the events. They can be published and subscribed to via Apex in addition to the APIs.


As Mohith commented, there are differences with the limits between Platform Events and the Streaming API.

E.g.

  • Maximum number of topics (PushTopic records) per org
    UE: 100 EE: 50 All other editions: 40
  • Maximum streaming channels per org
    UE: 1,000 EE: 1,000 PE: 1,000 Free: 200
  • Maximum number of platform event definitions that can be created in an org
    UE: 100 EE: 50 All other editions: 5

Another interesting difference is that PushTopics are limited to 2,000 clients/subscribers across all topics for Unlimited Edition orgs. Where as for the Generic Streaming that limit is 2,000 clients/subscribers per generic streaming channel.

Platform events have limits on subscribers documented in Platform Event Allocations. They differ based on edition and subscriber type.


From What Is the Difference Between the Salesforce Events?

Platform Events

Platform events enable you to deliver secure, scalable, and customizable event notifications within Salesforce or from external sources. Platform event fields are defined in Salesforce and determine the data that you send and receive. Apps can publish and subscribe to platform events on the Force.com Platform using Apex or in external systems using CometD.

Streaming API Events

Streaming API provides two types of events that you can publish and subscribe to: PushTopic and generic. PushTopic events track field changes in Salesforce records and are tied to Salesforce records. Generic events contain arbitrary payloads. Both event types don’t provide the level of granular customization that platform events offer. You can send a custom payload with a generic event, but you can’t define the data as fields. You can’t define those types of events in Salesforce, and you can’t use them in Apex triggers.

4
  • 4
    The platform events have greater limits than streaming .The No of push topics are limited for an org .Platform Events seems to have lot more run way in terms of limits . Commented May 30, 2017 at 2:58
  • @MohithShrivastava Good point. I've added some details about the limits. Commented May 30, 2017 at 8:44
  • @DanielBallinger, this section should be updated, "Platform events don't currently have a documented limit on subscribers". Per Salesforce, "The concurrent client allocation applies to CometD and to all types of events: platform events, change events, PushTopic events, and generic events." Source: developer.salesforce.com/docs/…
    – Plinderman
    Commented Sep 21, 2023 at 22:40
  • @Plinderman I've updated the link out to Platform Event Allocations for the various subscriber limits, as they vary by edition and subscription mechanism used. Commented Sep 21, 2023 at 22:54
15

Another significant differences -

  • In streaming API's we lose the update (event) if the subscriber is offline, however in platform events they will be available in the event bus for a duration of 24 hours. So if a subscriber comes online after sometime, he will still have access to updates happened during outage time.

    [Update] Same can be achieved for streaming APIs using Durable push topics.

  • Platform events are a first class object, that means you can setup multiple fields and can have your own structure to publish events. It wasn't possible on streaming APIs, as you had to rely on object fields which can be part of query.

  • Streaming APIs push updates were managed by the system, however Platform events needs to be fired manually. It will add additional responsibility to manage scenarios for platform events, where SF transaction failed but event has been pushed to Event bus.
2
  • 2
    For the 24 hour duration. My understanding is that the same applies to the Streaming API. Via Message Durability. So a subscriber could potentially catch up with events within the last 24 hours. Commented May 30, 2017 at 2:01
  • umm interesting. Thanks for adding that @DanielBallinger Commented May 30, 2017 at 2:48
1

Well, platform event is part of streaming API. Comparing to push topic and generic event, it is more pub-sub driven and offers more flexibity in terms of payload and handling.

Reference:

enter image description here

Reference: https://developer.salesforce.com/blogs/2019/07/a-refresher-on-the-four-streaming-apis-and-a-monitoring-tool.html

1
  • Just couldn't agree with the most voted answer that streaming api is mainly for UI. Streaming api is a big set of all those 4 types of events (Generic, pushtopic, platform events, change data capture). Most external systems used those 4 event type for data sync and exchange, UI is just small part of it.
    – Wayne Ni
    Commented May 6, 2021 at 1:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .