I'm struggling to understand how to improve the performance for an HTTP Request that comes with a huge body.
Now, let me explain better what I mean with performance!
Imagine I have a DB with the table "User" that contains 100k elements: if the client wants to visualize all of them, we can:
- Send 100k elements all together;
- Paginating the requests, so for instance sends 1k elements and 1k more when the user will scroll.
Easy to say, we would rather use the second option: sending 100k elements will have a huge impact. So far so good!
Now, how can thing works the other way around?
Imagine the web-client is able to edit the records he just downloaded and he wants to save the changes on the DB: he will call something like https://mysite/api/update
and pass a body with the update elements.
Let's also suppose the client has scrolled all the way down and he downloaded all 100k elements; the first and easiest improvements is to send back to the server ONLY the elements
that the web-client actually edited.
Now, imagine the web-client has edited all 100k elements (not very common, but still.. This is more a "I want to know" question).
What are the possibilities here? I can send one HTTP request to https://mysite/api/update
with the body containing 100k, but that seems really.. "bad". I mean, it will take forever for the webclient to send it, and the request itself may fail due to timeout.
First thing I thought was: well, just split the single request in multiple ones! So send 100 requests with 1k elements.
This may work, but.. all the requests should modify the database "once", meaning, if the last element update throws an error, NO element should be updated. So, I should perform all the requests and update in the DB as a transaction, but.. We have 100 different request.
The problem with the first "half solution" is that.. If the server is stateful, I might manage to perform the 100 different request in one go, but what if the server is stateless? Each request is completely standalone, so.. How this could work?
The only thing I think it may work is signalR: I open the connection and send elements split in different signalR message, but.. is this a god solution?
Finally, I also thought: well, maybe we can improve this by compressing the HTTP request body! I could use https://www.npmjs.com/package/pako
to compress from my JavaScript web-client, but.. I've read that web-client shouldn't really compress the HTTP request body (possible attacks like GZIP bomb).
IRepository
, and from there the database is updated. It's done this way because the "other Server" it's used in different places.Server that exposes methods implementing IRepository, and from there the database is updated
if the commit is Service-to-Service, then you are limited by the remote service interface. Is the remote service under your control? Can you add new features, for example, add new endpoints or even a second API?