Objective
In this tutorial iam going to show how can a tipical microservice architecture can be along with real world example and codebase
Technologies used
- Frontend
- Angular 8
- Angular material design v10
- websocket
- Backend
- spring boot 2.3.11
- spring cloud Hoxton.SR11
- MySql 8.0 CE
- Redis community edition
Architecture
Archiecture i thought of before starting the project
Github repositories
Spring backend services
Game backend
This service has core logic of game like calculation of winning logic, creating and destroying game’s. I have used concepts for
- websocket –> for real time game loading on a multiplayer environment
1 2 3 4
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency>
- redis cache –> for faster accessibility of data and auto deletion of game data if its ideal for sometime
1 2 3 4
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
- spring security resource server –> to maintain and authorize logged in users to maintain there game history
1 2 3 4
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
- feign client –> for microservices to microservice communication, feign client is a cloud service you should also have spring cloud services in your pom.xml
1 2 3 4 5 6 7 8 9 10 11
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
1 2 3 4
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
- kafka –> for communication with notification service
1 2 3 4
<dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka</artifactId> </dependency>
Game history service
This service maintains game history of authenticated users
- JPA –> for relational db calls it helps to remove all boiler plate code and gives simple interface to connect and execute db queries
1 2 3 4
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
- spring batch –> for deleting history data more than 90 months, runs every day to pick and delete records its configarable
1 2 3 4
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-batch</artifactId> </dependency>
Oauth2 service
This service authenticate and authorize users of game. This service issues JSON web tocken which will used by frontend to call other services. For every authenticated user it issues 2 token auth token(valid for 30min) and refresh token(valid for 1yr, can be used to generate more auth tokens).
- spring security –> to authenticate and authorize users
1 2 3 4 5 6 7 8 9
<dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
References
- This repository i forked from here