Technology advances in many ways: new materials, better integration of individual components, more elements, and so on. Yet one of the most visible features that sets today's electronic devices apart from those of a dozen years ago is size. There is no hiding that technical progress also means miniaturization, following the rule that the less space something takes up, the more of it fits in. This rule applies to hardware, but it can also be applied to software, although in a somewhat different form. Here too we are dealing with smaller applications and more of them. But that is not all, because the goal is not always just to make applications faster.

Today we will explain what microservices are and when their advantages show up. Since microservices are strictly a backend matter, for balance we will also talk about the less often mentioned concept of microfrontends, and for dessert we will touch on microframeworks. In short, today's text is sponsored by the word "micro", although the length of the article may not show it. Microcontrollers are missing to complete the set, but that is not quite the part of IT we work in.

The terms "frontend" and "backend" will come up very often in this article. If they are still unclear to you, we recommend reading our other text first.

What are microservices?

To explain this concept, we first need to recall what services are, or more precisely web services. These are resources on the World Wide Web made available through a special web interface. This interface is most often REST, which means exposing resources through HTTP requests. Using such services usually looks similar to opening pages at given URLs, except that the result is not HTML but most often data in XML or JSON. Web services act as the backend of an application, the part that "touches" the database directly and is responsible for delivering data, saving it and performing calculations.

So web services are made available through an application that lets you get individual pieces of functionality at specific addresses. That sounds fine and fairly simple, but the bigger the system gets, the more problems appear. First, a large application quickly becomes quite complicated (the "mess" grows more slowly the better the quality of the code), which can speed up the appearance of bugs. Second, a single application makes it harder to handle incoming traffic in heavily loaded services. Then, in the name of scaling, the backend is very often replicated across several servers. That is not always possible or convenient to configure, and a large application copied several times inevitably needs a better machine. Third, deploying changes to a single backend is not only harder but also requires stopping the system to swap in the new version (in the most basic case, of course).

All this means that very demanding and extensive systems call for a different solution. One was developed some time ago and is used successfully. It consists of splitting one backend application into several smaller ones, each responsible for a given functional scope. Yes, it can mean that instead of one backend we will have a few, a dozen or even more. Where are the advantages?

First, microservices are separate applications, much smaller than one whole backend, so they are easier to maintain and let you focus on a given domain area of the system (a group of related functions). They can also be designed more dynamically, because if something changes, only one small piece of code is affected rather than a huge system (everything depends on the case, of course).

Second, there are many advantages for deployment and maintenance. A small application is easier to replicate than a large one. That means microservices greatly favor scaling and replication. Most importantly, because the individual sub-applications are developed independently of each other, they are also deployed independently. That is why, when a bank announces a maintenance window, it can say which services will keep working and which will not. The whole backend does not have to be swapped on the server, only its individual parts. That is a big simplification, of course, but it is important to understand the concept.

Third, microservices are better from the team management point of view. With very large backends the number of developers is also large, which makes it hard for the project manager to keep track of everything. If we split the backend into smaller parts handled by separate groups, each independent, then monitoring progress and reacting to problems suddenly gets easier, because everyone has their own "backyard" and stays out of others' way. We can also recall the "two pizza" rule introduced by Jeff Bezos (former CEO of Amazon), which says a team should be so small that two pizzas are enough to feed all its members.

Fourth, because microservices are independent applications, they do not have to be written in one technology. Of course, you should not overdo it and build every service in a different language or framework, but there are situations where one functional part is much easier or more sensible to build in, say, Python, and another in Java. In practice there are also cases where a part of the system must be exceptionally fast, and it is worth building it in a different technology focused strictly on speed and/or throughput. The case of the creators of the game Gwent is worth a look: to improve the server architecture of the card game, they combined services written in PHP and Go.

So far we have listed advantages, so for balance let us also mention the drawbacks of microservices, because they exist too. They are mainly related to complexity. Each microservice application is indeed smaller and needs a smaller team, but the architecture of the whole system built on small services is quite complex. It needs at least preliminary planning, as well as a good administration and DevOps backbone. Setting up the whole infrastructure so that the smaller applications can be used conveniently is complicated and sometimes needs a separate team dealing only with that. In short, there is no point in introducing microservices where an ordinary backend application is entirely sufficient and meets the performance, throughput and functional needs. Remember that if the system grows and the need arises, you can redesign the backend and "extract" pieces that will form individual microservices (although it is, of course, easier to do it right away).

It is also worth stressing that while deploying individual applications is simple, maintaining the whole infrastructure can be difficult for smaller (and not only smaller) teams. That is why containerization came to the aid of microservices, and tools such as Docker, Podman, containerd and Kubernetes became popular. Thanks to this concept, managing the individual parts of the system and above all deploying them became much simpler. In addition, containers solve the problem of conflicting library versions needed by individual services, both on the server and on the developer's computer. For example, containerization makes it easier to keep one application written in PHP 7.4 and another using the benefits of PHP 8.1 running side by side. Of course, microservices do not require containers and containers do not require microservices, but it is hard to deny that splitting software into smaller applications fits very well with the concept proposed by Docker, for example.

What are microfrontends?

Someone may rightly ask: if the backend can be split into smaller applications, does the same apply to frontends? The answer is yes, but differently, and it is probably less widespread.

It is worth noting that splitting a frontend into separate panels aimed at individual groups of users is quite common. For example, an education portal may have a separate application for students, parents and teachers. Each will look similar, but may differ in color, for instance, and offer different functionality. In such a setup the individual panels usually live under separate subdomains. That is not what we would call microfrontends, though. These are entirely separate applications that do not "know" about each other and are not connected. It can even be a single website that looks slightly different inside and offers different things depending on the role of the user who logs in.

Microfrontends are about something else: here one interface is physically split into parts handled by separate teams. With microservices we could imagine such a split as more "islands" offering different functions, with the client (as a client application) addressing a specific one. With an interface split into parts, we are talking more about building one panel out of blocks that are, in fact, other applications. That way there is one "master" piece of software that forms the base displayed to the user, and inside itself it can show elements, each of which is really a separate piece of software in the background and, as with the backend, can ultimately be written in a different language. Older readers who were into building websites may remember the concept of frames. If frames were separate applications, we would call them microfrontends.

This has the same advantages as with the backend: for very complex applications, managing software development and deployment gets easier. But it also introduces the need to assemble the whole, which is problematic at the start and even unnecessary baggage for small companies and/or small applications. That is why microfrontends are not common, which does not mean the concept is bad. Every idea simply has to be adapted and used in an environment that really needs it.

And how does this "gluing" work technically? In various ways. There are dedicated frameworks, but you can also use the good old iframe. You will find more details under the links below:

What are microframeworks?

For dessert we have saved one more concept that seems to echo the earlier "micro terms" but is in practice something entirely different. We mentioned that various frameworks are used to build web applications (and not only). Some are better established, others less so, but what interests us now is that most of them are "engines" containing the tools needed for almost every aspect of software, except very specific solutions. I mean well-known options like Yii 2.0, Laravel, Symfony, Spring, NestJS, Django, .NET Core and others.

But sometimes developers do not need to build large applications that will last for years and prepare their structures over a long time. What is more, there is not always time to learn the rules of a large framework just to create a small API, or when we know the technology will change in the future anyway. That is why microframeworks appeared. They are really small engines that handle only the key elements of, for example, a web application. And truly key ones: there is no session management, database connection, validation and so on. If a developer needs these components, they have to write them or pick suitable libraries. But that is exactly why microframeworks suit simple tasks, such as a quick API for a larger application or for some test. Because of their size, learning one is fairly easy and does not take much time.

Contrary to appearances, neither microservices nor microfrontends are usually built with microframeworks. Remember that despite their small size, separate applications on the frontend or backend side are full-fledged pieces of software that handle various cases, such as user authentication and authorization. This means each of them needs, if not "heavy artillery", then a complete toolset. That is why "normal" frameworks are most often chosen for them. It does not mean micro-scale ones are useless, just that they have a different use.

Examples of better-known microframeworks are Slim and Lumen (PHP), Bottle and Flask (Python), Spark (Java), Sinatra (Ruby) and Express.js (Node.js). Quite recently Framework X also appeared. It is aimed squarely at building APIs and looks like an interesting solution, focusing on something PHP is not known for: asynchronous processing.

Summary

This article aimed to explain the idea of microservices and microfrontends. Both terms are about splitting applications into smaller parts that are easier to deploy and let an IT company divide responsibility better. Still, keep in mind that like any tool in the software development process, the ones discussed here have consequences and come with broader configuration work to hold all the parts together. That is why they are intended rather for large systems, or ones where specific parts need special treatment. For dessert we mentioned microframeworks, even though they are not conceptually related to the earlier topics.

Best regards and thank you - Jakub Rojek.