Skip to main content
  1. Posts/

Understanding the macro of microservices

·4 mins

In the world of software development, microservices have become a buzzword but what exactly are microservices, and why should you care? In this post, we’ll explore what microservices are, their use cases, the technologies involved, common patterns, challenges, and more useful things to help you get on track.

What Are Microservices? #

Microservices vs Monolith
Microservices vs Monolith

Microservices architecture is a design approach where an application is built as a collection of small, independent services that communicate with each other. Each service is responsible for a specific piece of functionality and can be developed, deployed, and scaled independently. This contrasts with a monolithic architecture, where all components of the application are tightly coupled into a single unit.

I bet you already knew this, but what about what means “micro”? There is no strict rule for it but you have to keep in mind a few things:

  • Single Responsibility Principle: Should focus on one specific business capability or function.
  • Manageability: Should be small enough to be easily understood and managed by a single team.
  • Independence: Should be deployable and scalable independently.

To achieve the previous points we also have to think about using a database per microservice, otherwise it would be a centralized point of failure right? this will lead us to choosing the right database considering database propagation,replication and inconsistent states. This is another topic but I recommend reading my post ACID vs BASE, things to know before taking the decision.

While some teams use microservices with a shared SQL database (this is not a sin), it brings a few considerations to our project like reading queue and performance degradation.

Use Cases #

Microservices are ideal for a variety of scenarios:

  • Large, Complex Applications: When an application grows in complexity, breaking it into smaller, manageable services can make development and maintenance easier.
  • Scalability: If different parts of your application have varying scalability needs, microservices allow you to scale each component independently.
  • Technology Diversity: If your application needs to use different technologies or programming languages, microservices enable you to choose the best tool for each job.

Technologies #

To build and manage microservices, you’ll need a range of technologies:

  • Containers: Tools like Docker help in packaging microservices along with their dependencies, making deployment consistent across environments.
  • Orchestration: Kubernetes manages containerized applications, handling scaling and deployment across clusters.
  • Service Discovery: Tools like Consul or Eureka help services find and communicate with each other.
  • API Gateways: Solutions like Zuul or Nginx manage and route traffic between clients and services, handling cross-cutting concerns such as authentication and logging.
  • CI/CD Pipelines: Jenkins, GitLab CI, and similar tools automate the build, test, and deployment processes.

Common Patterns #

Microservices architecture often employs certain patterns to address common challenges:

  • API Gateway Pattern: This pattern uses a single entry point for all client requests, routing them to the appropriate microservice. It can handle authentication, logging, and request aggregation.
  • Circuit Breaker Pattern: To handle service failures gracefully, this pattern prevents a failure in one service from cascading to others by stopping calls to a failing service.
  • Saga Pattern: For managing distributed transactions across multiple services, the saga pattern orchestrates a sequence of local transactions with compensating actions if needed.

Challenges #

Despite its benefits, microservices architecture comes with its own set of challenges:

  • Complexity: Managing multiple services can be complex, especially with inter-service communication, data consistency, and deployment orchestration.
  • Latency: Communication between services over a network can introduce latency compared to in-process communication in monolithic systems.
  • Data Management: Ensuring data consistency and handling distributed transactions can be tricky with multiple databases.
  • Monitoring and Debugging: Tracking and diagnosing issues across multiple services require sophisticated monitoring and logging tools.

Is Microservices a Good Approach for Small Projects? #

For small projects, microservices might be overkill. The overhead involved in managing multiple services, setting up communication, and handling deployment can outweigh the benefits. A monolithic architecture might be more suitable for smaller applications where simplicity and faster development are priorities.

Is It More Expensive? #

Microservices can be more expensive due to:

  • Infrastructure Costs: Running multiple services can lead to higher infrastructure costs, especially if each service requires its own resources.
  • Operational Overhead: The complexity of managing, monitoring, and scaling multiple services can increase operational costs.
  • Development Time: The initial setup and configuration of microservices can be time-consuming.

Is It More Difficult to Update? #

Updating a microservices-based system can be challenging:

  • Dependency Management: Changes in one service might require adjustments in others, making coordination important.
  • Versioning: Managing different versions of services and ensuring backward compatibility can be complex.

However, microservices can also facilitate easier updates in the long run, as individual services can be updated independently without affecting the entire system.

Conclusions #

Every team has to evaluate the pros and cons of using microservices. Some teams get excited too fast about the scaling idea but don’t fully understand the considerations of dealing with microservices, updating them, monitoring them, working in a local environment and many more details. If they are not a good fit for your company and project they can make your development and release cycle slower compared to a monolithic approach and increase the cost of your application.