Microservices explained - the What, Why and How?

TechWorld with Nana · Beginner ·☁️ DevOps & Cloud ·3y ago

Key Takeaways

Explains microservices architecture, including monolithic to microservices transition, monorepo vs polyrepo, and microservices connectivity

Full Transcript

in this video i'm going to talk about microservices first i'm going to start by explaining what a monolith application architecture is what were some of the challenges of a monolith architecture and why the industry moved slowly towards the microservices architecture then we will see what microservices or microservice architecture is exactly as well as best practices benefits and how the communication between microservices actually works we will also see different ways to manage code for microservices application and talk about monorepo versus polyrepo and advantages and disadvantages of both so let's get started before microservices the standard way of developing applications was with a monolithic architecture this means all the components of the application the whole code basically is part of a single unit for example if we had an online shop application all of its parts like the user authentication shopping cart product catalog sales campaigns notification and so on all the code for these functionalities would be in one code base as part of one monolithic application everything is developed deployed and scaled as one unit this means the application must be written in a single language with one technology stack with a single runtime and if you have different teams working on different parts of the application they will need to coordinate to make sure they don't affect each other's work also if developers change code for the payment functionality you would need to build the whole application and deploy it as one package you can't just update and deploy only the payment functionality changes separately so this was a standard way of developing applications but as applications grew in size and complexity this led to different challenges first of all the coordination between teams became more difficult because the code was much bigger and the parts of the application were more tangled into each other also if suddenly you had a usage spike in shopping cart for example on holiday dates and you would want to scale only that part of the application you can't do it you need to scale the whole application this in turn means higher infrastructure costs and less flexibility in scaling your application up and down another issue is for example if a payment functionally used a third-party module with a version 1.8 while notifications featured needed the same module but required the version 1.7 instead in a monolith application you would have to pick one or the other because it's a single application and you can only have one dependency of the same module another major issue with monolith applications is that the release process of such applications takes longer because for changes in any part of the application in any feature you need to test and build the whole application to deploy those changes and the answer to all these issues was a microservices architecture so what is microservices exactly with microservices we break down the application in essentially multiple smaller applications so we have several small or micro applications that make up this one big application now we have a couple of very important questions when we create a microservices architecture first of all how do we decide how to break down the application what code goes where and how many such micro applications or microservices do we create how big or small should these microservices be and finally how do these services then talk to each other first of all the best practice is to break down the application into components or into microservices based on the business functionalities and not technical functionalities so the microservices of an online shop application will be products shopping cart user accounts checkout and so on because all these are basically business features and in terms of the size each micro service must do just one isolated thing so you should have a micro service that is responsible for shopping cart logic and the checkout you should always strive to keep one service doing one specific job and a very important characteristic of each microservice is that they should be self-contained and independent from each other this means each service must be able to be developed deployed and scaled separately without any tight dependencies on any other services even though they are part of the same application and this is called lose coupling so with this best practice approach if you change something in the payment service you will only build and deploy the payment service nothing else will be affected and this means the services have their own individual versions which are not dependent on others so if i release one service i don't need to release any other service so the this release cycle has to be completely independent now if these services are isolated and self-contained how do they connect to each other because obviously the payment service will need something from the user account to process the payment or the checkout service will need something from the shopping cart a very common way for microservice communication is using api calls so each service has an endpoint on which it accepts requests from other services so services can talk to each other by sending each other http requests on these endpoints this is a synchronous communication where one service sends a request to another service and waits for the response so the user account service can send an http request to payment service on its api endpoint and vice versa another common way of communication between microservices is using a message broker with an asynchronous communication here services will send messages first to the intermediary message service or a broker such as rabbitmq for example and then the message broker will forward that message to the respective service so again user account will send the message to the broker saying please pass this message on to the payment service and message broker will then forward that message to the payment service and a third way of communication between microservices which is becoming pretty popular especially in the field of kubernetes is using a service mesh with service mesh you have kind of a helper service which takes over the complete communication logic so you don't have to code this logic into the microservices and have this communication logic kind of delegated to this external service so these are different communication options and since the services are all isolated and talk to each other either with api calls or using additional services you can even develop each service with a different programming language and you can have dedicated teams for each service that can choose their own technology stack and work on their service without affecting or being affected by other service teams and this is exactly the most important advantage of microservices architecture compared to the monolith however these benefits come with the price so while microservices made developing and deploying applications easier in many aspects it also introduced some other challenges that weren't there before when you break down the application into these multiple pieces this introduces a lot of complexities and challenges one of the main complexities may be configuring the communication part between the services because a micro service may be down or unhealthy and not responding yet while another service starts sending requests to its api expecting a fulfilled response in which case you may get unexpected results also with microservices deployed and scaled separately it may become difficult to keep an overview and find out when a microservice is down or which service is actually down when something in the application is not working properly so you definitely need a proper configuration of your application setup and its pieces to make sure your application as a whole functions well but there are various tools for making all this easier so even though the microservices architecture is complex there are a lot of tools and still more being developed regularly to make running microservices applications easier the most popular one you probably already know is kubernetes which is a perfect platform for running large microservices applications now before moving on i'm very excited to give a shout out to hashicorp which is a company that many of you probably already know about and has a lot of really cool technologies many of those that actually solve various challenges when working with microservices applications from the infrastructure provisioning tool terraform to the secret management tool vault which is pretty much becoming a standard already in the industry for managing and protecting your sensitive data hashicorp also has a service mesh product called console which helps you securely connect and observe your microservices running in any environment so with various tools that hashicorp offers you can actually provision secure connect and run cloud infrastructure for your most important applications and specifically for your microservices applications if you want to learn more about any of these technologies be sure to check out the whiteboard sessions of hashicorps co-founder and cto who gives really good introductions of all these technologies on youtube and now let's move on now obviously an important element of deploying microservices is a cicd pipeline in fact there are many companies with microservices applications that deploy multiple times a day companies like amazon google and netflix they have applications with hundreds of microservices that they deploy thousands of times per day so you can imagine the complexity and the sophistication of their csd pipelines so in the modern world and workplace you will be most probably working with microservices and in this case you would need to know how to configure release process with a cicd pipeline for microservices now we said microservices is when application components get developed and deployed separately as individual micro applications so the question is how do we manage the code for microservices application in a git repository like gitlab for example with one project it's simple we just have one application and it gets its own git repository with microservices application we have two options for how the code is managed monorepo which stands for single repository and polyrepo also multi-repository so monorepo or single repository is having one gitlab repository for all the services so we would create one project for a monorepo so what's the difference here or how do we structure multiple micro applications inside one application repository well a common way is using folders so you have folders for each service like shopping cart payment notifications etc and all the code for those services are in those respective folders and having a mono repo meaning all the services still in one repository makes the code management and development easier because you only have to clone and work with one repository so it simplifies things plus if you have some shared code between the services like kubernetes manifest templates or helm chart or docker compose whatever you can put them in the root of the project and all the services can basically reuse them but monorepo also comes with some challenges as i mentioned the most important criterion of microservices is to be completely independent and isolated so no tight coupling between the services inside the code and it becomes easy to break this criterion when you have a monorepo so you have junior developers with less experience in the monorepo setup it's easier to make such mistakes and develop tightly coupled logic or code in your services another downside of monorepo is when the application becomes really big cloning fetching and pushing becomes slow because your project is huge and in terms of the csd pipeline in most of the ci cd platforms like gitlab csd or jenkins you can only create one pipeline for one project so you are building multiple services with a single project pipeline and that means you need to add additional logic in your pipeline code that makes sure to only build and deploy the service which has changed so if you make code changes in the payment service your pipeline code should detect that and only that service should be built tested and deployed and it is possible to do that but it's a little bit more challenging one more issue with a monorepo is that since you have just one main branch because you have one repository if developers of one of the services break the main branch other services and their pipelines will be blocked as well but there are a lot of companies including very big ones like google who actually use monorepo for their applications the second option which is probably a bit more preferred one is polyrepo or multiple repositories with this approach for each service we create a separate git project so the code is completely isolated you can clone and work on them separately because they are in separate repositories now even though they are separate application repositories they are still part of this bigger application so of course you would want to still have some kind of connection of these repos for an easy management and overview so if you're hosting your code repositories on gitlab for example you can use gitlab's feature of groups in order to group code for all the microservices that belong to the same application in one group to make managing those repositories easier so essentially you would create a gitlab repository group for your application called my online shop and inside this group you can create a separate project for each microservice that belongs to that application if your company has multiple microservices applications of course this will help keep an overview of what projects belong together but also within the group you can actually create secrets or other ci variables that can be shared by all the projects in that group now what about the cicd pipeline for a polyrepo well for polyrepo the csd configuration is more straightforward because you just have own pipeline for each repository so no extra logic is needed to differentiate between the services now of course everything has advantages and disadvantages so for polyrepo as well you have some downsides like having application code in multiple repositories can make working on the project as a whole harder especially if you need to change two or more services at once because a feature or bug fix affects multiple services if you need to switch between the services often this can also be tedious plus things like searching something across multiple projects from the code editor can be difficult or impossible also in the polyrepo you can't really share files in the project like kubernetes or hell manifest docker compose and so on you would either have to duplicate them in each project's repository or have to create a dedicated project and reference them from there so as you see both options have their advantages and disadvantages but the general rule is that if you have a small project with just a several microservices you should stick to monorepo and save the overhead of creating and managing and checking out multiple repositories on the other hand if you have separate teams for each service if you want to have complete isolation smaller code base to clone on pipelines and so on then of course the polyreport would be a better option now i hope this gave you a great introduction to microservices and now you understand what it is and why everyone is using it if you're interested to know how to build ci cd pipelines for a micro service applications then you can check out my complete gitlab ci cd course in which i actually show hands-on demos of how to build ci cd pipelines for micro service applications in a mono repo as well as poly repo as well as deploying a micro service application to a kubernetes cluster and generally if this video was useful please give it a like and share with your colleagues and subscribe for more content like this with this thank you for watching and see you in the next video

Original Description

What are Microservices | Monolithic to Microservices Architecture | Monorepo vs Polyrepo | How Microservices connect with each other 💛 Follow me on IG for behind-the-scenes-content ► https://bit.ly/2F3LXYJ 💚 Become a DevOps Engineer - 6-month program: ► https://bit.ly/3ou15W0 🧡 GitLab Course with Microservices, K8s, Multi-Stage: ► https://bit.ly/3Ww1LXN #microservices #devops #techworldwithnana ► This video is sponsored by HashiCorp 🙌🏼 ► For more infos about their technologies: https://www.hashicorp.com/ In this video you will learn all you need to know about Microservices in 18 minutes. First, I will start with what a Monolithic Architecture is, what are some of its challenges and why the industry moved slowly towards the microservices architecture? Then we will see what microservices or a microservice architecture is exactly, the best practices, benefits and how the communication between microservices works. And finally we will also look at the downsides or challenges of a microservices architecture. We will also see different ways to manage code for microservices application and talk about the difference of monorepo and polyrepo and advantages and disadvantages of both! ▬▬▬▬▬▬ T I M E S T A M P S ⏰ ▬▬▬▬▬▬ 00:00 - Intro and Overview 00:43 - Monolith & its challenges 03:18 - What are Microservices exactly? 05:28 - How Microservices communicate with each other? 07:58 - Downsides of Microservices 10:40 - CI/CD Pipeline for Microservices 11:24 - Monorepo vs Polyrepo - How to manage the code for microservices application? 12:03 - Monorepo explained - Benefits and Disadvantages 14:46 - Polyrepo explained - Benefits and Disadvantages 17:17 - Which one to choose when? ▬▬▬▬▬▬ Want to learn more? 🚀 ▬▬▬▬▬▬ Full Python course ► https://youtu.be/t8pPdKYpowI Full Docker course ► https://youtu.be/3c-iBn73dDE Full K8s course
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from TechWorld with Nana · TechWorld with Nana · 0 of 60

← Previous Next →
1 What is Docker? Docker container concept explained || Docker Tutorial 1
What is Docker? Docker container concept explained || Docker Tutorial 1
TechWorld with Nana
2 What is a Docker Container? Docker Demo || Docker Tutorial 2
What is a Docker Container? Docker Demo || Docker Tutorial 2
TechWorld with Nana
3 How to install docker? Step by Step || Docker Tutorial 3
How to install docker? Step by Step || Docker Tutorial 3
TechWorld with Nana
4 8 Basic Docker Commands || Docker Tutorial 4
8 Basic Docker Commands || Docker Tutorial 4
TechWorld with Nana
5 Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
Debugging Docker Containers with docker exec and docker logs || Docker Tutorial 5
TechWorld with Nana
6 Docker vs Virtual Machine | simply explained || Docker Tutorial 6
Docker vs Virtual Machine | simply explained || Docker Tutorial 6
TechWorld with Nana
7 Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
Overview of Workflow with Docker - Docker in Practice || Docker Tutorial 7
TechWorld with Nana
8 Developing with Docker - Docker in Practice || Docker Tutorial 8
Developing with Docker - Docker in Practice || Docker Tutorial 8
TechWorld with Nana
9 Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
Docker Compose Tutorial - Docker in Practice || Docker Tutorial 9
TechWorld with Nana
10 Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
Dockerfile Tutorial - Docker in Practice || Docker Tutorial 10
TechWorld with Nana
11 Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
Private Repository explained | Registry on AWS - Docker in Practice || Docker Tutorial 11
TechWorld with Nana
12 Docker Volumes explained in 6 minutes
Docker Volumes explained in 6 minutes
TechWorld with Nana
13 Deploying the containerized application with Docker Compose || Docker Tutorial 12
Deploying the containerized application with Docker Compose || Docker Tutorial 12
TechWorld with Nana
14 Docker Volumes Demo || Docker Tutorial 13
Docker Volumes Demo || Docker Tutorial 13
TechWorld with Nana
15 Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
Docker vs Kubernetes vs Docker Swarm | Comparison in 5 mins
TechWorld with Nana
16 What is Kubernetes | Kubernetes explained in 15 mins
What is Kubernetes | Kubernetes explained in 15 mins
TechWorld with Nana
17 Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
Kubernetes Components explained! Pods, Services, Secrets, ConfigMap | Kubernetes Tutorial 14
TechWorld with Nana
18 Kubernetes Architecture explained | Kubernetes Tutorial 15
Kubernetes Architecture explained | Kubernetes Tutorial 15
TechWorld with Nana
19 Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
Benefits of Kubernetes | Scalability, High Availability, Disaster Recovery | Kubernetes Tutorial 16
TechWorld with Nana
20 Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
Minikube and Kubectl explained | Setup for Beginners | Kubernetes Tutorial 17
TechWorld with Nana
21 Top 3 programming languages to learn in 2020 | meta analysis
Top 3 programming languages to learn in 2020 | meta analysis
TechWorld with Nana
22 Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18
TechWorld with Nana
23 Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
TechWorld with Nana
24 Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
Run Jenkins in Docker Container - Jenkins Pipeline Tutorial for Beginners 1/4
TechWorld with Nana
25 Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
Create Multibranch Pipeline with Git - Jenkins Pipeline Tutorial for Beginners 2/4
TechWorld with Nana
26 Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
Jenkinsfile - Jenkins Pipeline Tutorial for Beginners 3/4
TechWorld with Nana
27 Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
Trigger Jenkins Build automatically - Jenkins Pipeline Tutorial for Beginners 4/4
TechWorld with Nana
28 Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
Complete Application Deployment using Kubernetes Components | Kubernetes Tutorial 20
TechWorld with Nana
29 Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
Kubernetes Namespaces Explained in 15 mins | Kubernetes Tutorial 21
TechWorld with Nana
30 Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
Configure Build Tools in Jenkins and Jenkinsfile | Jenkins Tutorial
TechWorld with Nana
31 Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
Complete Jenkins Pipeline Tutorial | Jenkinsfile explained
TechWorld with Nana
32 Kubernetes Ingress Tutorial for Beginners | simply explained  | Kubernetes Tutorial 22
Kubernetes Ingress Tutorial for Beginners | simply explained | Kubernetes Tutorial 22
TechWorld with Nana
33 What is Helm in Kubernetes? Helm and Helm Charts explained  | Kubernetes Tutorial 23
What is Helm in Kubernetes? Helm and Helm Charts explained | Kubernetes Tutorial 23
TechWorld with Nana
34 How Websites Work | simply explained with examples
How Websites Work | simply explained with examples
TechWorld with Nana
35 What is JavaScript? | JavaScript Tutorial #1
What is JavaScript? | JavaScript Tutorial #1
TechWorld with Nana
36 What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
What is Ansible | Ansible Playbook explained | Ansible Tutorial for Beginners
TechWorld with Nana
37 JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
JavaScript Variables & JavaScript Data Types explained | JavaScript Tutorial #2
TechWorld with Nana
38 How Prometheus Monitoring works | Prometheus Architecture explained
How Prometheus Monitoring works | Prometheus Architecture explained
TechWorld with Nana
39 Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
Where to write JavaScript | Where to execute JavaScript Code | JavaScript Tutorial #3
TechWorld with Nana
40 JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
JavaScript Operators & JavaScript Conditionals | JavaScript Tutorial #4
TechWorld with Nana
41 Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
Pods and Containers - Kubernetes Networking | Container Communication inside the Pod
TechWorld with Nana
42 Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
Kubernetes Volumes explained | Persistent Volume, Persistent Volume Claim & Storage Class
TechWorld with Nana
43 Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
Kubernetes ConfigMap and Secret as Kubernetes Volumes | Demo
TechWorld with Nana
44 Pull Image from Private Docker Registry in Kubernetes cluster | Demo
Pull Image from Private Docker Registry in Kubernetes cluster | Demo
TechWorld with Nana
45 Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
Kubernetes StatefulSet simply explained | Deployment vs StatefulSet
TechWorld with Nana
46 Yaml Tutorial | Learn YAML in 18 mins
Yaml Tutorial | Learn YAML in 18 mins
TechWorld with Nana
47 Terraform explained in 15 mins | Terraform Tutorial for Beginners
Terraform explained in 15 mins | Terraform Tutorial for Beginners
TechWorld with Nana
48 Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator | Part 1
TechWorld with Nana
49 Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
Managed Kubernetes Cluster explained | Kubernetes on Cloud (1/2)
TechWorld with Nana
50 Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
Step by Step Application Deployment on LKE using Helm | Kubernetes on Cloud (2/2)
TechWorld with Nana
51 Kubernetes Operator simply explained in 10 mins
Kubernetes Operator simply explained in 10 mins
TechWorld with Nana
52 What is Infrastructure as Code? Difference of Infrastructure as Code Tools
What is Infrastructure as Code? Difference of Infrastructure as Code Tools
TechWorld with Nana
53 AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
AWS EKS - Create Kubernetes cluster on Amazon EKS | the easy way
TechWorld with Nana
54 Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
Prometheus Monitoring - Steps to monitor third-party apps using Prometheus Exporter | Part 2
TechWorld with Nana
55 GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker
TechWorld with Nana
56 Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
Docker Tutorial for Beginners [FULL COURSE in 3 Hours]
TechWorld with Nana
57 Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
Kubernetes Services explained | ClusterIP vs NodePort vs LoadBalancer vs Headless Service
TechWorld with Nana
58 Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours]
TechWorld with Nana
59 Containers on AWS Overview: ECS | EKS | Fargate | ECR
Containers on AWS Overview: ECS | EKS | Fargate | ECR
TechWorld with Nana
60 Kubernetes is dropping Docker support - What does it mean for YOU?
Kubernetes is dropping Docker support - What does it mean for YOU?
TechWorld with Nana

Related Reads

📰
Deploying and Configuring Apache on a RHEL/CentOS Server
Learn to deploy and configure Apache on a RHEL/CentOS server for web hosting and development purposes.
Medium · DevOps
📰
Put a Deterministic Gate Between Generated Code and Main
Learn to add a deterministic gate between generated code and main to improve code quality and reduce errors
Dev.to · kongkong
📰
How to Put a Local Service on the Public Internet with FRP (Without Losing Your Mind Over Config Files)
Learn to expose a local service to the public internet using FRP, simplifying config files
Dev.to · ChenXX
📰
Four GitHub Actions cron timing bugs that silently broke my daily pipelines
Learn about four common GitHub Actions cron timing bugs that can silently break daily pipelines and how to identify and fix them
Dev.to · MORINAGA

Chapters (10)

Intro and Overview
0:43 Monolith & its challenges
3:18 What are Microservices exactly?
5:28 How Microservices communicate with each other?
7:58 Downsides of Microservices
10:40 CI/CD Pipeline for Microservices
11:24 Monorepo vs Polyrepo - How to manage the code for microservices application?
12:03 Monorepo explained - Benefits and Disadvantages
14:46 Polyrepo explained - Benefits and Disadvantages
17:17 Which one to choose when?
Up next
AWS, Azure, GCP: The One Thing Every Business Gets Wrong
AI Daily
Watch →