Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calvinmclean/sandwiches
This is an example of a simple Go microservices application
https://github.com/calvinmclean/sandwiches
Last synced: 21 days ago
JSON representation
This is an example of a simple Go microservices application
- Host: GitHub
- URL: https://github.com/calvinmclean/sandwiches
- Owner: calvinmclean
- Created: 2019-06-14T20:36:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-09T20:36:32.000Z (over 5 years ago)
- Last Synced: 2023-03-06T19:16:58.177Z (almost 2 years ago)
- Language: Go
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sandwich Shop Microservices
### How to use
Start with `docker-compose up`
Then, you can visit http://localhost/clerk/order to create a sandwich by giving a sandwich ID and listing extra ingredient IDs like: `1 2 3`. This is not very fancy but it works for now.
Ordering from the Clerk is the only interactive part of the program at the moment. Other links can be explored to get JSON responses:
| Link | Purpose |
| :----------------------------- | :---------------------------------------------- |
| http://localhost/menu/show | show the menu (this one is plain text not JSON) |
| http://localhost/menu/ | get the menu JSON |
| http://localhost/menu/1 | get the first item on the menu |
| http://localhost/ingredients | get all ingredients |
| http://localhost/ingredients/1 | get the first ingredient |
| http://localhost/recipes | get all recipes |
| http://localhost/recipes/1 | get the first recipe |## Microservices
This program is composed of 4 different services and an Nginx proxy. The microservices are:
1. Clerk: responsible for handling purchases
- This is an effective microservice because all it does is receive information from users and then requests additional information from other services in order to return information to the user
- This can be scaled to increase simultaneous order processing2. Ingredients: holds a list of ingredients and their prices
- This is an effective microservice because it only handles one thing: ingredients. It exists to provide information about ingredients to other services3. Menu: holds a list of recipes and their prices to serve to users
- This is an effective microservice because it just holds a list of menu items that can be requested by the Clerk. It relies on the Ingredients and Recipes microservices to provide up-to-date and accurate information when creating the menu
- Since all values are from other services, if the price of an ingredient changes or a new recipe is added, the menu will be able to easily update its information4. recipes: holds a list of recipes and their required ingredients
- This is an effective microservice because it simply serves information about recipes to the Menu service## Event-driven aspects of this program/service
| Event | Response | Implemented? |
| :------------------------- | :------------------------------------------------------------------------------------------ | :----------- |
| Ingredient price change | trigger an event in the Menu service to update the prices of all items with that ingredient | No |
| New recipe is added | trigger an event in the Menu service to add the new recipe to the menu | No |
| Customer visits store page | clerk requests menu from Menu service | No |
| Customer submits order | clerk consults Menu and Ingredients to calculate price | Yes |## Current drawbacks
**Note**: Some of these event-response ideas are not implemented because they require more aspects of a RESTful API that I haven't programmed yet. Also I am currently using YAML files instead of a database to hold information about recipes and ingredients which also makes it more difficult to change/update recipes and ingredients.
**Note**: Currently the `models.go` file is required by each service so I just copy it to each directory. If this was a more robust service, the models would be published on Github and imported by each service.