[SalesForce] the difference between the Streaming API PushTopic, Generic Streaming and Platform Events

Salesforce offers two variants of the Streaming APIPushTopic 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?

Best Answer

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 don't currently have a documented limit on subscribers.


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.