Jumping in Microservices

Monolith Vs Microservices: Knowing The Difference

What is a Monolith?
A monolithic application is built as a single, unified unit. Often a monolith consists of three parts: a database , a client-side user interface (consisting of HTML pages and/or JavaScript running in a browser), and a server-side application. The server-side application will handle HTTP requests, execute domain-specific logic, retrieve and update data from the database, and populate the HTML views to be sent to the browser.

Another characteristic of a monolith is that it’s often one massive code base. Server side application logic, front end client side logic, background jobs, etc, are all defined in the same code base. This means if developers want to make any changes or updates, they need to build and deploy the entire stack all at once.

Monolith Pros:
  1. Fewer Cross-cutting Concerns: A major advantage associated with monolithic architecture is that you only need to worry about cross-cutting concerns, such as logging or caching, for one application.
  2. Less Operational Overhead: Focusing your finances on one application means that there’s only one application that you need to set up logging, monitoring and testing for. A  Monolith is also generally less complex to deploy since you aren’t organizing multiple deployments.
  3. Easier Testing: With a monolith, automated tests are easier to setup and run because, once again, everything is under the same roof. With microservices, tests will need to accommodate for different applications on different runtime environments — which can get complex.
  4. Performance: A monolith can also boast  performance advantages in comparison to microservices. That’s often down to a monolith using local calls instead of an API call across a network.
Monolith Cons:
  1. Overly-tight Coupling: While monoliths can help you avoid entanglement as previously mentioned, a monolith becomes more vulnerable to entanglement the larger it grows. Because everything is so tightly coupled, isolation of services within the monolith becomes arduous, making life difficult when it comes to independent scaling or code maintenance.
  2. Harder To Understand: It’s common to find that monoliths are more difficult beasts to understand in comparison to microservices, a problem which rears its head when on-boarding new team members. This is sometimes a direct result of the tight coupling, as well as the fact that there may be dependencies and side-effects which are not obvious when you’re looking at a particular service or controller.

What Are Microservices?
Microservice architecture refers to the concept of developing a single application as a suite of small services, in contrast to developing them as one, large ‘monolith’.

Each of those broken-up, individualized services  run on their own process, communicating with lightweight mechanisms, often an HTTP resource API. Fully-fledged microservices are independently deployable, and yet can work in tandem when necessary.

Microservices Pros:
  1. Better Organization: Microservice architectures are typically better organized, since each microservice has a very specific job, and is not concerned with the jobs of other components.
  2. Decoupled: Decoupled services are also easier to recompose and reconfigure to serve the purposes of different apps (for example, serving both the web clients and public API). They also allow for fast, independent delivery of individual parts within a larger, integrated system.
  3. Performance: Under the right circumstances, microservices can also have performance advantages depending on how they’re organized because it’s possible to isolate hot services and scale them independent of the rest of the app.
  4. Fewer Mistakes: Microservices enable parallel development by establishing a hard-to-cross boundary between different parts of your system. By doing this, you make it hard – or at least harder – to do the wrong thing: Namely, connecting parts that shouldn’t be connected, and coupling too tightly those that need to be connected.
Microservices Cons:
  1. Cross-cutting Concerns Across Each Service: As you’re building a new microservice architecture, you’re likely to discover lots of cross-cutting concerns that you did not anticipate at design time. You’ll either need to incur the overhead of separate modules for each cross-cutting concern (i.e. testing), or encapsulate cross-cutting concerns in another service layer that all traffic gets routed through. Eventually, even monolithic architectures tend to route traffic through an outer service layer for cross-cutting concerns, but with a monolithic architecture, it’s possible to delay the cost of that work until the project is much more mature.
  2. Higher Operational Overhead: Microservices are frequently deployed on their own virtual machines or containers, causing a proliferation of VM wrangling work. These tasks are frequently automated with container fleet management tools.

Testing microservices vs testing monoliths

Right off the bat, microservices require extra steps like managing multiple repositories and branches, each with their own database schemas. But the challenges can run deeper than that.

Here are a few key challenges associated with testing microservices:

  1. Availability: Since different teams may be managing their own microservices, securing the availability of a microservice (or, worse yet, trying to find a time when all microservices are available at once), is tough.
  2. Fragmented and holistic testing: Microservices are built to work alone, and together with other loosely coupled services. That means developers need to test every component in isolation, as well as testing everything together.
  3. Knowledge gaps: Particularly with integration testing (which we will address later in this chapter), whoever conducts the tests will need to have a strong understanding of each service in order to write test cases effectively.

When To Start With A Monolith

Here are some scenarios that indicate that you should start your next project using monolithic architecture.

  1. Your Team Is At Founding Stage: Your team is small, between 2-5 members, and is thus unable to tackle a broader and high-overhead microservices architecture.
  2. You’re Building An Unproven Product or Proof of Concept: Are you building an unproven product in the market? If it’s a new idea, it’s likely going to pivot and evolve over time, so a monolith is ideal to allow for rapid product iteration. Same applies to a proof of concept where your goal is just to learn as much as possible as quickly as possible, even if you end up throwing it away.
  3. You Have No Microservices Experience: If your team has no prior experience with microservices, unless you can justify taking the risk of learning “on the fly” at such an early stage, it’s likely another sign you should stick to a monolith to start.

When To Start With Microservices

Here are some scenarios that indicate that you should start your next project using microservices:

  1. You Require Quick, Independent Service Delivery: If it’s snappy, isolated service delivery that you need, microservices are your best bet. However, depending on the size of your team, it can take some time before you see any service delivery gains versus starting with monolith.
  2. A Piece of Your Platform Needs to Be Extremely Efficient: If your business is doing intensive processing of petabytes of log volume, you’ll likely want to build that service out in a very efficient language (i.e. C++) while your user dashboard may be built in Ruby on Rails.
  3. You Plan To Scale Your Team: Starting with microservices gets your team used to developing in separate small teams from the beginning, and having teams separated by service boundaries makes scaling your development organization easier.

Reference (Highly recommend reading these article)

As these articles are really long to read, I will recommend adding this extension to Chrome. Read Aloud: A Text to Speech Voice Reader

  • The Ideal Definition
  • What is and why is Microservices

  • Monolith Vs Microservices: Knowing The Difference
  • Pro & cons of Monolith and Microservices
  • Monolith Vs Microservices: How To Decide
  • When To Start With A Monolith
  • When To Start With Microservices

  • The importance of microservice boundaries
  • Characteristics of a well-designed service
  • Considerations for larger teams
  • How to tell if a service is too small, or not properly defined
  • Consider these characteristics
  • Common microservice testing methods
  • Testing microservices vs testing monoliths
  • Five microservice testing strategies for startups
  • Microservice testing: difficult, but worth it

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )