I'm trying to write a DRF view to wait for an event

Hello, i have a problem with a process in my app and i would like to know if someone had a similar one :-/

1.- An user owner of a shop creates an order in the db.
2.- This order has to be accepted by a rider who is going to deliver the products to different addresses
3.- The rider can press accept or reject.
4.- Whether the action is accept or reject, the order creator(the shop) has to be able to see this response in the UI(not mandatory), so he/she can create again a new order or just wait for the rider to pick up the goods in the shop and go for delivering.

In the past i did it with an Ajax querying the db every 10 seconds from the template but is not the best approach since there can be hundreds of users executing this script at the same time.

I’ve been digging in the Django channels but also i don’t need it for the whole application, i just need this event check up in this specific step in the app flow.

I’m running out of ideas and i can not find a solution for it :-/

I would appreciate a lot any help i can receive.

Thanks in advance!

If you had 1000 users all trying to do this at the same time, then you’re talking on average about 100 requests / second.

If you have that level of activity, then you should be able to afford multiple endpoints for handling this. (It could be a separate Django instance to just handle those monitoring requests, or it could use a different stack altogether to quickly report on the status.)

Aside from that, you don’t have too many real choices. You’re either going to deal with ~100 requests / second, or you’re going to need to manage 1000 concurrent connections.

However, before making any decisions, you should probably do some real-world load and performance testing to determine at what stage your system starts to fail.

At what point now do things start to fail?

If you can’t answer that question, then everything else is pure conjecture.

1 Like

For now it’s just pure conjeture, i’m developing an app similar to Domino’s Pizza or Papa John’s, i think another option would be sending a notification and an e-mail whenever a rider generates an event so i don’t need to use asyncronous processes maybe?

You can add a check status button to load the status of all the orders and leave it up to the user, when he wants to see it. Or perhaps email would be better if you want to notify him.

1 Like

Thanks g-kartik! Indeed i will set up a notification + e-mail to notify the shop. The button idea is amazing, i’ll think about it!