Each vending machine will have an embedded server & database and respond to its own apis. It will occasionally make network requests to update a central database with analytical information & contact a payment processor to handle payments. It may also send out alerts to event subscribers. Largely however it will do local embedded operations to serve customers.
Data warehouse
this will recieve diagnostic info from the vending machine for reporting purposes.
Event service
will alert staff when vending machines need maintance
Authentication service
when staff attempt to enter maintenance mode, ensures that they are authorized to do so
Vending machines:
Will have a simple, embedded relational database like sqllite. This gives us ACID properties witout needless network calls. This database will store the inventory and keep a local history of trasnactions. The vending machine will also need a physical point of sale device to handle payments & a physical scanner so it knows what is in its inventory. Here is how each api is implemented.
The vending machine will be designed with a State Machine design pattern. In each state only certain operations are avaialble
Data warehouse
This stores data across all vending machines for analytical workloads. Assuming that this can be a day behind, each vending machine can update the data warhouse with its information during off hours in batched jobs. We would not want every vending machine to perform this update at once, but would spread it out over time, vending machines 1-10 during the first hour, 11-20 in the second etc. If there are few enough vending machines, we should keep these jobs in off hours to save money on cloud compute, otherwise we can do these jobs thoughout the day. Once the records are confirmed to be in the data warhouse, we can remove the records from the local vending machine databases. These only need to know their current inventory for smooth operation purposes.
Event service
When vending machines either enter an invalid state or are low on inventory they should send an alert to an employee dispatch service. THen this service can page the relevant team to go and assist. These events can be queued in a message queue to then be processed and resolved by the pager service.