Travel, tech and food

Microservices 101

A brief introduction

Confronting developing applications using microservices can be a bit scary like any step into the unknown, but they can offer many benefits over the traditional monolithic approach to application development. Microservices can offer a smarter way to develop software that is more reliable, scalable and maintainable and make much better usage of cloud computing resources. They are a practical expression of modular programming Рdefined by OUP Dictionary of Computing as:

A style of programming in which the complete program is decomposed into a set of components, termed modules, each of which is of manageable size, has a well-defined purpose, and has a well-defined interface for use by other modules. 

Daintith, J., & Wright, E. (2008). modular programming. In  (Ed.), A Dictionary of Computing. : Oxford University Press,. Retrieved 9 Jan. 2019, from http://www.oxfordreference.com/view/10.1093/acref/9780199234004.001.0001/acref-9780199234004-e-3304.

A lot of popular applications in recent years have been developed separating data, presentation and logic following Model-Viewer-Controller design patterns. Although these applications have been organised nicely they were still monolithic in nature and even in MVC applications you can find a spaghetti of interlinked classes. These applications can become unwieldy to maintain and scale efficiently. To make modern, reliable, scalable high-volume applications we should go back to the architecture drawing board and redesign our applications using microservices.

How do microservices make life easier in terms of maintenance and scalability? Microservices architecture divides an application into services which are responsible for a well defined, specific domain e.g. authentication, billing or shipping etc. They can operate independently and interact with other services using requests over HTTP to provide the whole application.

This means we can design the services so that if one stops working the rest can carry on functioning. When we need to scale each service we can do so individually, making better use of computing and storage resources compared to scaling entire applications. Since microservices are independent of each other, they can also be written in different languages as appropriate for their particular task.

There are still challenges in writing and maintaining microservices. Deployment is more complex than just uploading some PHP files to a server, although continuous integration and containerisation can be make deploying microservices fairly trivial. When it comes to debugging, it is a more complex task since you need to trace the area to a specific instance of a microservice and get the logs, although there are ways to centralise logging which mitigate this.

Since each service is self-contained you may also now be developing with different platforms, databases and languages, which means your team may have to keep on top of more technologies than before. It makes sense for people to take ownership of services but this can lead to isolated pools of knowledge. As ever, it’s important to communicate effectively so that services integrate well and play nicely. When done right, microservices architecture can make developers lives easier and the products we work on more powerful and dependable.

Further Reading

https://dzone.com/articles/quotwhy-do-you-always-choose-microservices-over-me

https://www.cio.com/article/2924995/software/what-are-containers-and-why-do-you-need-them.html

https://microservices.io/

Image from sxcii (CC license)