Table of Contents
This project is created from scratch to evaluate the possibility of microservices architecture.
- Authentication
- Product management (Create and Sell ticket)
- View and purchase product
- Stripe integration for payment
- Event-Driven Architecture using NATS Streaming Server as Event bus
- Optimistic Concurrency Control (OCC) for handling concurrency issues
- Implement worker service using Bull Queue
- JWT Authentication
- Server side rendering with Next.js
List of major frameworks/libraries used to bootstrap the project.
Folder | Detail |
---|---|
auth | Service to handle authentication (signup/signin/signout) |
client | The client application (Next.js) |
common | The commmon service that used in every service and it's uploaded to npmjs.com |
infra | Kubernetes infrastucture for this application |
nats-test | Testing to NATS Streaming Server |
orders | Order service |
tickets | Ticket service |
payments | Service for handling payment processes |
expiration | Expiration worker for locking ticket during payment waiting |
skaffold.yml | Skaffold configuration for this project |
For more information, please refer
This is an instruction on setting up the project locally. To get a local copy up and running follow these simple example steps.
- Docker
- Kubernetes
- Skaffold
-
Get a free Stripe API Key at https://stripe.com
-
Clone the repo
git clone https://github.com/dragonxsx/microservices-ticketing.git
-
Install NGINX Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/cloud/deploy.yaml
-
Generate ssl certificate and create tls secret
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ssl-key.key -out ssl-cert.cert -subj "/CN=ticketing.dev/O=ticketing.dev" kubectl create secret tls ticketing --key ssl-key.key --cert ssl-cert.cert
-
Create secret environment variables
kubectl create secret generic jwt-secret --from-literal=JWT_KEY=${YOUR_JWT_KEY} kubectl create secret generic stripe-secret --from-literal STRIPE_KEY=${YOUR_STRIPE_KEY}
-
Change local environment hosts file
Edit hosts file
- For Windows: C:\Windows\System32\drivers\etc\hosts
- For Mac/Linux: /etc/hosts
Add new line
127.0.0.1 ticketing.dev
-
Bootstrap the application
skaffold dev
Error: mongo can't be pulled
Try pulling the image manually from outside of Skaffold:
docker pull mongo
If this is successful, it should cache it locally and the problem will no longer persist.
secret "jwt-secret" not found
kubectl create secret generic jwt-secret --from-literal=JWT_KEY=${YOUR_JWT_KEY}
503 service temporarily unavailable
Delete and re-install ingress controller
- Get the namespace which your ingress controller installed in
for example : ingress-nginx
kubectl get ns
- Remove all resources in this namespace
If your ingress controller is not installed in a dedicated namespace so you will have to remove resources one by one.
kubectl delete all --all -n ingress-nginx
kubectl delete ingress ingress-nginx kubectl delete deployment ingress-nginx kubectl delete service ingress-nginx
- Install ingress controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/cloud/deploy.yaml
Nguyen Thanh Long - @dragonxsx
Project Links: