A RESTful API to serves coffees, powered by goroutines.
This project was done during GopherCON UK 2023, during Sadie's Freeman (@sadief) workshop.
- it has to be scalable and fast!
- Server coffee without concurrency
- Server more than 1 coffee
- Add concurrency: use goroutines
- Add WaitGroup: Why? to make sure that all goroutines we start will also finish
- Add more goroutines: so we can run each function concurrent
- in root folder run
make run
to start the docker container - navigate to
http://localhost:8080/serve-coffee/50000
to hit the endpoint and try making MANY coffee. Checkout the logs to see the time it took to make them. In my case, 50000 coffee took 13.390567749s - in root folder run
make down
to stop the docker container and remove image.
- Scale vertically by adding more pods
Configuration 1
resources:
limits:
cpu: 1
memory: 3092M
requests:
cpu: 1
memory: 1024M
// Took 5.057038683s to serve coffee, customer no: 50000
Configuration 2
resources:
limits:
cpu: 4
memory: 3092M
requests:
cpu: 2
memory: 1024M
Took 9.362377223s to serve coffee, customer no: 50000
Why? 🤔
https://github.com/sadief/gophercon-2023-slides-code/tree/main