I create an application for ordering and delivering products from supermarkets. After making an order and processing it by the store, it is necessary that this order be taken by the nearest driver. In this case, the customer must see in real time the status of his order and the location of the driver.
I plan to divide the logic into a real-time server (RTS) and a business logic server. (WLAN)
- The tasks of the WLAN will include: authorization of users and drivers (JWT tokens), receiving and processing orders, the payment system.
- RTS will be used to monitor the locations of all drivers and create a connection on web sockets. The driver will have to constantly send his location from the GPS to be online
Communication RTS-BLS will occur using Redis pub / sub. In this case, part of the order data and driver information will be copied from MongoDB and stored in Redis. Thus, the information will be publicly available for all RTS servers (if I expand horizontally the architecture). The search for the nearest driver to the order was originally planned through MongoDB Geosearch, but then we would have to constantly write down driver locations in MongoDB - which means a lot of calls to the database. Therefore, I want to implement a search for the nearest entity through Redis.
- WLAN uses Node.js + Express + Mongo
RTS uses Socket.io
Question:
- Did I design the application architecture correctly?
- How to implement driver authorization on the RTS, if all the logic for obtaining and creating tokens on the WLAN.
- Access tokens may become obsolete with time, but the driver may still be connected to the RTS server, do I need to disconnect the connection and ask the driver to login again on the WLAN and send me a new token?
- Which geo search will be faster using MongoDB or Redis?