Dataflow Diagram
Explanation:
-
The nextjs client is the front end of the application and it communicates with the express api server to get and post data to the worker server and the mysql database.
-
The express api server is the middle layer of the application. When it receives a post request from the nextjs client, it publishes a message to the redis pub/sub. When it receives a get request from the nextjs client, it checks the redis cache for the data. If the data is not in the redis cache, it sends a request to the database to get the data and caches the data in the redis cache for future requests. If the data is in the redis cache, it sends the data to the nextjs client. It is also responsible for sending responses to the nextjs client.
-
The worker server is a microservice that subscribes to the redis pub/sub and receives messages from the express api server when a post request is made from the nextjs client. It is responsible for sending requests to the mysql database to store the data.
Components:
- Nextjs Client
- Express Server
- Worker (Nodejs) Server
- Redis Cache and Pub/Sub
- MySQL Database
Following is a demonstration of the system:
Demonstration of the systemYou can try it out yourself by cloning the repo and following the instructions below.
git clone www.github.com/umarfchy/nextjs-express-redis-microservice-architecture
cd nextjs-express-redis-microservice-architecture
docker compose up
Thanks for reading!