Publish batches of events at scale with the Batch Events API

tigger_batch_events.jpg

Pusher is built to handle scale — every month we deliver 160 billion messages to 6.5 billion devices. Developers use Pusher to build scalable apps with millions of users, so they need to be able to push different events at the same time. We wanted to make this easy, so you can now publish a \[…\]

Introduction

Pusher is built to handle scale — every month we deliver 160 billion messages to 6.5 billion devices. Developers use Pusher to build scalable apps with millions of users, so they need to be able to push different events at the same time. We wanted to make this easy, so you can now publish a batch of events.

Pusher client libraries now allow you to send multiple distinct events in a single HTTP call using the Batch Events API method.

Efficiently scale with batches of events

Let’s say you have a message queue and you want to publish these messages more efficiently, you can batch events into one call.

Usually messages are published on a one-to-one with events, but if your app has logic to publish many different messages to channels based on one event, you can use publish them all at once with a batch call.

Limits

All of our multi-tenant clusters accept up to 10 events per request. If you need to send larger batches, we can offer this if you are on a dedicated cluster where other customers won’t get impacted by the higher load. If you’re interested in this, get in touch with us.

Fighting the HTTP overhead

Every HTTP call contains around 400 bytes in the request header. Depending on the size of the event this can represent up to a 10x overhead per event. But batching events into one call solves this by making fewer calls.

How does this work?

Batching is particularly well suited if the events are fetched from a message queue or generated in the process itself. Here is an example in ruby where “events” is an unbounded list of events.

Before:

1events.each do |(channel, event_name, data)|
2  pusher.trigger(channel, event_name, data)
3end

After:

1events.each_slice(10) do |events|
2  pusher.trigger_batch(events)
3end

It’s important to note that this is for multiple unique events, if you’re looking to send the same event to multiple channels use the POST event instead.

Update to the client libraries

All of our official client libraries have been updated, as well as the documentation for batch events. The feature is available in the following versions or newer:

  • Go v1.2.0
  • Java v1.0.0
  • .NET v3.0.0
  • Node v1.3.0
  • PHP v2.4.0
  • Python v1.3.0
  • Ruby v1.1.0

Any other existing client libraries can be updated by following the spec (or ask support if you need the support for another language).

Feedback

We’re always thrilled to see how our tools help developers solve problems. Give batch events a spin and then send us your feedback.