Microservices with Spring Boot

A while ago I was working on a demo project using Vue.js, you can find it here. The demo only included front-end code, no back-end components at all. I was looking for a modern approach to create a scalable back-end, hence microservices!

Setup

A configuration server starts and pulls the configuration for several components from a very simple git repository, it looks like this:

This is the content for 'travel-attraction-service.yml', it contains information about which port the server should run on, how to connect to its database and where to find Eureka (Netflix service registry):

Almost every component in the setup registers itself with Eureka (except the configuration server).

Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers.

Eureka keeps track of all registered services and uses naming convention to map/load balance calls. The use of Eureka will be become more clear in the next section.

API Gateway

All requests from the client (postman, angular webapp...) will be send to the API Gateway, this component is responsible for routing requests to their desired endpoint. We use Zuul from Netflix in this setup.

Zuul is the front door for all requests from devices and web sites to the backend of the Netflix streaming application. As an edge service application, Zuul is built to enable dynamic routing, monitoring, resiliency and security. It also has the ability to route requests to multiple Amazon Auto Scaling Groups as appropriate.

All requests starting with '/auth' will be routed to the authentication server, it uses Eureka behind the scenes to map the name (travel-auth-server) to a real IP.

Authentication server

For the authorization I use OAuth2, I am not going to discuss the framework in detail, I am no security experts by any means, you'll find enough material on the interwebs.

Simply put, a request send to the token endpoint with the correct credentials (password grant type) will return an access token that can be used to send authorized request to other services in the stack.

Flyway will automatically create a metadata table that will keep track of already executed files.

Postman calls

Here is a collection of Postman calls that you can use to test the microservices.

Conclusion

Spring Boot makes creating microservices a piece of cake, their integration with components written by Netflix is a god sent. I do have some thinking left about the following:

How can I prevent port conflicts for 2 instances of a microservice, the configuration has a fixed port.

Should I keep the secret for the oAuth2 integration, seems kind of useless to me in a client side application where obfuscation is impossible.

Dockerizing the services shouldn't be to hard, maybe something for a future post?

Between coding the setup and writing this post some time has passed. I've continued reading articles on the topic and found out about Kubernetes by Google.

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best-of-breed ideas and practices from the community.

Kubernetes seems to simplify things even further, components like Eureka could be completely replaced! It's is very interesting but also very new, the learning curve seems steep.