GoogleCloudPlatform / cloud-functions-reliability-nodejs

Apache License 2.0
17 stars 5 forks source link

On-demand Rideshare Service Example App for firebase cloud Functions (Uber/Lyft Clone) #2

Open Radecom opened 5 years ago

Radecom commented 5 years ago

I am designing a clone uber system with Firestore, Cloud Messaging and Functions of Firebase. I have a function that runs when a new order is created (OrdersRef.onCreate ()).

Diagram Rideshare Dispatch

Obviously, I execute the tasks of:

Get the currently available cars. For each available car, I get the distance between the location of the car and the pick-up point of the order. I order the cars by the distance of their location and the point of collection of the order. ** I have the exception if the array of available cars is empty, the function ends.

So far everything is going well. But here you ask me, what is the best way to carry out the car dispatch?

I can think of 2 ways:

The first would be to send a notification to the nearest driver with the order data, wait 9 sec (sleeping the cloud function with a sleep function), after waiting 9 seconds, make a new query to get the current status of the order, and if it has not yet been taken, I send a new notification to the next driver ... and so on until I run out of my array of available cars. ** We have to remember that in cloud functions (backend) queries to Firestore are promises and not observable as in frontend frames (angular).

The second would be to schedule notifications and queries with pub/sub and make a review similarly ... Send a notification to the nearest driver with the order data, and program with Pub / Sub a function that will check in the next 9 seconds if the order has already been taken, if I do not send the notification to the next driver and reschedule a new function with Pub / Sub to recheck ... and so on until my array of available cars runs out.

The problem with the first form is that the function can last a long time in execution.

The problem with the second form is that a function can be converted into many subfunctions.

My question here is: What is the best way to do this?

Could you give an example to guide us like this Pubnun?

Crewnie commented 5 years ago

I think it is a great idea, please consider doing such a guide to help us with that way.