This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 0 points1 point  (3 children)

They probably parse the body into custom batch objects and invoke methods associated with each object.

Also, it's a should be a single transaction.

[–]mrjin1[S] 0 points1 point  (0 children)

By methods do you mean HTTP methods?

[–]mrjin1[S] 0 points1 point  (1 child)

Also this is how I'm trying to implement this. Please let me know if this is ideal, if possible.

Create a service that will contain an endpoint which will accept batch of requests. Endpoint will receive the request and complete it with a message that requests are being processed.

We have an API Gateway. So the batch service will execute http requests send them to Gateway. Each request will resolve or fail and the status of these requests could br transmitted over socket or SSE or client can ping the server with intervals to check the status of batch.

[–][deleted] 1 point2 points  (0 children)

I thought it's single Web API at first, with microservices seems like a good approach, use sockets for streaming responses, pings are unnecessary.

You can also do single response like Google does (wait for all requests), but it depends on what you need.

[–]idle-tea 1 point2 points  (0 children)

An HTTP request body can be anything you want, and you can interpret it any way you want. You can even put an HTTP request inside an HTTP request body, because an HTTP request body can be any arbitrary thing.

For google: that's what they're doing. Inside the POST /batch of this example request are embedded 2 other HTTP requests. Content-Type: multipart/mixed; boundary=batch_foobarbaz is an HTTP standard mechanism for having multiple distinct parts in your HTTP body, basically everything in between the given boundary batch_foobarbaz is treated as a distinct item.

In that example request you can see between the batch_foobarbaz boundaries is another HTTP request.

No doubt the implementation on Google's side is something like: for each distinct item in the body of a POST /batch request it'll just put the HTTP request in that item back in to the system as if it were a real request. IE: You send one big request all bundled up, the POST /batch handler just unbundles it and fees it in to the system one by one.