18 Batch operations

 

This chapter covers

  • Batch operations and their differences from executing a series of standard methods
  • Why batch operations should be atomic
  • How batch request methods can hoist common fields to avoid repetition
  • An exploration of each batch standard method (get, delete, create, and update)

This pattern provides guidelines by which users of an API can manipulate multiple resources in bulk without making separate API calls. These so-called batch operations behave similarly to the standard methods (discussed in chapter 7), but they avoid the necessity of multiple back-and-forth interactions of multiple API calls. The end result is a set of methods that permit retrieving, updating, or deleting a collection of resources with a single API call rather than one per resource.

18.1 Motivation

So far, most of the design patterns and guidelines we’ve explored have been focused on interacting with individual resources. In fact, we’ve taken this even further in chapter 8 by exploring how to operate even more narrowly, focusing on addressing individual fields on a single resource. While this has proven quite useful thus far, it leaves a gap on the other end of the spectrum. What if we want to operate more broadly, across multiple resources simultaneously?

18.2 Overview

18.3 Implementation

18.3.1 Atomicity

18.3.2 Operation on the collection

18.3.3 Ordering of results

18.3.4 Common fields

18.3.5 Operating across parents

18.3.6 Batch Get

18.3.7 Batch Delete

18.3.8 Batch Create

18.3.9 Batch Update

18.3.10 Final API definition

18.4 Trade-offs

18.5 Exercises

Summary