Request Batch

This post was originally published on this site

Martin Fowler

Solution

Combine multiple requests together into a single request batch. The batch of the request will be sent to the cluster node for processing. with each request processed in exactly the same manner as an individual request. It will then respond with the batch of the responses.

As an example, consider a distributed key-value store, where the client sends requests to store multiple key-values on the server. When the client receives a call to send the request, it does not immediately send it over the network; instead, it keeps a queue of requests to be sent.

class Client…

LinkedBlockingQueue<RequestEntry> requests = new LinkedBlockingQueue<>(); public CompletableFuture send(SetValueRequest setValueRequest) { int requestId = enqueueRequest(setValueRequest); CompletableFuture responseFuture = trackPendingRequest(requestId); return responseFuture; } private int enqueueRequest(SetValueRequest setValueRequest) { int requestId = nextRequestId(); byte[] requestBytes = serialize(setValueRequest, requestId); requests.add(new RequestEntry(requestBytes, clock.nanoTime())); return requestId; } private int nextRequestId() { return requestNumber++;

To read the full article click on the 'post' link at the top.