We had this interesting project at work: design and implement a Thrift-like code generator but for RESTful services. Thrift uses IDL files where you can define the contract of a service, including the data structures (or entities) it accepts and returns. Thrift will generate code of the client and the service in programming language of choice. The only problem is that it’s not RESTful and that’s what we needed.
The task was interesting but it got me thinking that it would be nice to avoid code generation. I tried to get to the roots of why we needed the microservices architecture in the first place. Usually, the reasons are:
Many development teams and software companies use certain tools because they are “modern” or “trending”. To give you an example, a company may be upgrading from Zend Framework 1 to Symfony 2 simply because it’s newer and not for Symfony2’s specific features. That is actually an okay approach because often you don’t have time to solve all problems yourself or even realize that you have problems. By using modern technologies you rely on experience of larger community.
However for an engineering department to have a competivie edge and be on top of the game it’s important and very much achievable to understand the exact reasons for choosing one architecture over another. Following that thought I came to the conclusion that more often than not only the first item is why micro service architecture is used:
That should be handled on a separate level, by creating abstractions, packages and modules. This is why we have OOP and Encapsulation. Separate VCS repositories should exist with appropriate permissions for owning development teams.
This is a valid reason, but from my experience this is often not needed, especially for internal APIs. Using different languages has its cons also, for example you will need to port and maintain all infrastructural code.
There is an otherwise great application, properly designed, loosely coupled, flexible and a breeze to maintain. The only issue is that we need to isolate and scale parts of it independently. I felt like this was a cross cutting concern that could be addressed by applying Aspect Oriented Programming. I implemented a proof of concept and a demo application that are available on GitHub: xrmi, xrmi Demo.
The demo is an online store application with classes
WarehouseService. At some point the load on WarehouseService forces us to scale it independently and use a cluster of machines with lots of operating memory. By using XRMI and AOP the demo application directs all calls to the WarehouseService to a remote instance:
all that happens transparently for the application.