Speeding up requests with feathers-batch

David Luecke
The Feathers Flightpath
2 min readOct 5, 2020

--

Today I’d like to highlight the new release of feathers-batch, a Feathers plugin that allows to execute multiple Feathers API requests in a single call. It now also comes with a client side module that automatically collects requests made from a Feathers client and turns them into a single batch call whenever possible. This can greatly improve the performance of frontends (or any other client) where multiple requests (especially via HTTP REST) are being made at the same time (e.g. on first page load or application startup).

If you are interested in how a Feathers plugin comes together and how it works under the hood, here is a recording of the live-coding session where I build the new feathers-batch from scratch:

On the fly live-coding feathers-batch hosted by Aquil.io

feathers-batch consists of two parts. The first is the server side batch service which is initialized like any other Feathers service:

Now the /batch service create method can be called to make multiple requests at once (see the documentation for the format on how to make batch calls manually). An additional performance improvement when batching authenticated calls is possible by adding the authenticate hook to the batch service so that authentication only runs once (instead of each call in the batch).

With the service set up, when using Feathers on the client we can use the client side module that will handle making batched calls whenever possible:

Now any request made on the client at the same time will be automatically added to a batch. You don’t have to change anything else to get the performance improvements of batch requests! For best results, also see the documentation on parallelizing requests.

I found feathers-batch to be another good example of the Feathers way. With 69 actual lines of code it is a small plugin that can lead to significant performance benefits without having to change anything in your existing application.

Get in touch with us on Twitter or in our Slack group.

If you are new to Feathers and looking to create your first app head on over to the docs and get your geek on!

--

--