Say we're developing an app (just like I am):
The web-part doesn't exist yet, it will be the web GUI (Spring boot MVC).
We have two small services:
- UserRegistration
- UserInfo
Since they use the same data I choose to group them with the same database.
So when we register a new user, the info will be sent to the UserRegistration-service by AMQP-message via RabbitMQ.
The UserRegistration-service puts the data in the database. To control the structure we make a POJO (JPA or other, depends on the database eg. MongoDB).
And there is the problem. The structure (the POJO) is in the UserRegistration-service project!
So when the UserInfo-service retrieves the data you probably want the same structure as you put it in.
There is probably more solutions but...
I see two obvious roads to go about:
- Make the services bigger and have all the user-related stuff in one big service
- Have a shared library with the code that needs to be shared
Personally I think option 1 is too risky. The service might become a giant service so the "micro"-part might disappear.
So how do we do option 2?
The code could either be a separate project and use some form of distributer to a artifact repository or try to make it part of one of the services (probably the one who puts it in the database) and try to package that part of the code some how.
This adds another level to the complexity. The need to share libraries, that the services can't be 100% independent.
This is a big part of the microservice architecture, it is somewhat complex. There is a lot of benefits to reap but you can probably solve this much easier in a monolith.
On the other hand there is a lot of benefits if you can get the microservices right:
- Fast development
- Independent deployment of services
- Scaling
- Services can be in different programming languages
So now I think I will deploy a Sonatype Nexus repository as a Docker-instance and share the User-structure.
To be continued...
Quick update:
After reading a bit about others experience concerning microservices another problem came to mind.
https://rclayton.silvrback.com/failing-at-microservices
If you have shared code between services, especially Models (entity structures) this is most likely written in a specific programming language. This takes away one of the aspects of microservices.
So how do we solve this? This will take some thinking (I would like a good place to discuss these problems). My first thought is to find some JSON-structure due to the AMQP and send all messages by JSON-format (formatted as Byte arrays). Hopefully this makes it possible to use the message in another language.
Quick update:
After reading a bit about others experience concerning microservices another problem came to mind.
https://rclayton.silvrback.com/failing-at-microservices
If you have shared code between services, especially Models (entity structures) this is most likely written in a specific programming language. This takes away one of the aspects of microservices.
So how do we solve this? This will take some thinking (I would like a good place to discuss these problems). My first thought is to find some JSON-structure due to the AMQP and send all messages by JSON-format (formatted as Byte arrays). Hopefully this makes it possible to use the message in another language.
And Happy New Year!