Ghun Kim
Ghun Kim

Reputation: 63

How do you handle high throughput functions in the REST API server?

I am developing the rest API using python flask. (Client is a mobile app)

However, important functions are a batch program that reads data from DB processes it, and then updates (or inserts) the data when a user requests POST method with user data

Considering a lot of Read, Write, and Computation

How do you develop it?

This is how I think.

  1. Use procedures in DB

  2. Create an external deployment program that is independent of API.

  3. Create a separate batch server

  4. Just run it on the API server

I can not judge what is right with my knowledge.

And the important thing is that execution speed should not be slow.

For the user to feel, they should look as though they are running on their own devices.

I would like to ask you for advice on back-end development.

Upvotes: 4

Views: 928

Answers (1)

logicOnAbstractions
logicOnAbstractions

Reputation: 2600

I would recommand considering asyncio. This is pretty much the use-case you have - i/o is time-consuming, but doesn't require lots of CPU. So essentially you would want that i/o to be done asynchronously, while the rest of the server carries on.

  • The server receives some requests that requires i/o.
  • It spins off that request into your asyncio architecture, so it can be performed.
  • The server is already available to receive other requests, while the previous i/o requests is being processed.
  • The previous i/o requests finishes. Asyncio offers a few ways to deal with this.

See the docs, but you could provide a callback, or build your logic to take advantage of Asyncio's event loop (which essentially manages switching back & forth between context, e.g. the "main" context of your server serving resquests and the async i/o operations that you have queued up).

Upvotes: 2

Related Questions