{"id":134,"date":"2024-01-17T22:24:28","date_gmt":"2024-01-17T22:24:28","guid":{"rendered":"https:\/\/hoclaptrinh.fun\/?p=134"},"modified":"2024-01-17T22:52:52","modified_gmt":"2024-01-17T22:52:52","slug":"microservices-interview-questions-part-1","status":"publish","type":"post","link":"https:\/\/hoclaptrinh.fun\/index.php\/2024\/01\/17\/microservices-interview-questions-part-1\/","title":{"rendered":"Microservices Interview Questions &#8211; Part 1"},"content":{"rendered":"\n\t<div id=\"text-2578442590\" class=\"text\">\n\t\t\n\n<p>Microservices are a popular way to structure software systems today. As companies grow bigger and use more cloud computing, microservices help tackle complexity.<\/p>\n<p>In this issue, we review some key microservices concepts and common questions that come up in interviews:\u00a0<\/p>\n<ol>\n<li>\n<p>What are microservices?<\/p>\n<\/li>\n<li>\n<p>What issues do microservices aim to solve?<\/p>\n<\/li>\n<li>\n<p>What new challenges do microservices introduce?<\/p>\n<\/li>\n<li>\n<p>What are some popular microservices solutions?<\/p>\n<\/li>\n<li>\n<p>How does monitoring and alerting work with microservices?<\/p>\n<\/li>\n<li>\n<p>How are logs collected and analyzed?<\/p>\n<\/li>\n<li>\n<p>What is a Service Registry?<\/p>\n<\/li>\n<\/ol>\n<div><hr \/><\/div>\n<p>Now let\u2019s start with the definition of microservices.<\/p>\n<h2 class=\"header-with-anchor-widget\">1. What Are Microservices?<\/h2>\n<p>We can quote from Martin Fowler and Adrian Cockcroft on key aspects of microservices.<\/p>\n<p>From\u00a0<a href=\"https:\/\/martinfowler.com\/articles\/microservices.html\" rel=\"\">Martin Fowler<\/a>:<\/p>\n<blockquote>\n<p>\u201cThe microservice architectural style is an approach to developing a single application as a suite of\u00a0<strong>small services<\/strong>, each running in its own process and communicating with lightweight mechanisms, often\u00a0<strong>an HTTP resource API<\/strong>. These services are built around business capabilities and\u00a0<strong>independently deployable<\/strong>\u00a0by fully automated deployment machinery. There is a bare minimum of\u00a0<strong>centralized management<\/strong>\u00a0of these services, which may be written in different programming languages and use different data storage technologies.\u201d<\/p>\n<\/blockquote>\n<p>From\u00a0<a href=\"https:\/\/www.infoq.com\/presentations\/microservices-netflix-industry\/\" rel=\"\">Adrian Cockcroft<\/a>:<\/p>\n<blockquote>\n<p>\u201cM<a href=\"http:\/\/www.slideshare.net\/adriancockcroft\/dockercon-state-of-the-art-in-microservices\" rel=\"\">icroservices are loosely coupled service-oriented architecture with bounded contexts<\/a>.\u201d<\/p>\n<\/blockquote>\n<h3 class=\"header-with-anchor-widget\">Key Aspects of Microservices<\/h3>\n<p>From the insightful definitions by Martin Fowler and Adrian Cockcroft, we can summarize these key aspects of a microservice architecture:<\/p>\n<ol>\n<li>\n<p>Decompose monolithic application into small, independent services. This allows different product teams to develop, test, and deploy services that align to specific business capabilities. Useful for large organizations to break down monolithic systems and improve productivity.\u00a0<\/p>\n<\/li>\n<li>\n<p>Loosely coupled services communicating via APIs. Frontend\/backend components communicate via REST, whil inter-service communications use RPC for efficient request\/response.<\/p>\n<\/li>\n<li>\n<p>Carefully designed around bounded contexts. Each service has clear module boundaries and encapsulated domain logic to avoid tight coupling between services.<\/p>\n<\/li>\n<li>\n<p>Enables effective DevOps practices. It is an important part of the microservice development methodology. Small, full-stack teams fully own specific services end-to-end. Containerization, automation, and container orchestration are used to effectively deploy microservices.<\/p>\n<\/li>\n<li>\n<p>Horizontally scalable by design, resilient to failures. Services can scale out independently as needed. Built with fault tolerance in mind.<\/p>\n<\/li>\n<li>\n<p>Decentralized governance and flexibility. Teams can choose whatever technology makes sense for their service.<\/p>\n<\/li>\n<li>\n<p>Requires extensive monitoring and instrumentation due to:<\/p>\n<ol>\n<li>\n<p>Growth in services &#8211; As monoliths decompose into many independent services, the number of components to track grows quickly.<\/p>\n<\/li>\n<li>\n<p>Infrastructure abstraction via containers\/orchestrators &#8211; Runtime platforms like Kubernetes handle infrastructure. So monitoring must happen at the application code level using sidecars to aggregate logs, metrics and traces.<\/p>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2 class=\"header-with-anchor-widget\">2. What Are the Differences Between SOA and Microservices?<\/h2>\n<p>Service-oriented architecture (SOA) and microservices architecture styles are important milestones in software architecture&#8217;s evolution. The diagram below shows the progression of key architectural styles.<\/p>\n<p>Service-oriented architecture emerged in the late 1990s to help manage enterprise software systems\u2019 growing complexity. In the 2000s, SOA gained more industry attention and adoption by companies. However, SOA faced implementation complexity challenges.\u00a0<\/p>\n<p>Then in the 2010s, microservices architecture emerged in response to SOA\u2019s limitations. Many large internet companies started adopting microservices to break down their services into smaller components. Microservices gained momentum with cloud computing\u2019s evolution, as containers and orchestration tools made microservices&#8217; development, deployment, and monitoring easier.<\/p>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-145 aligncenter\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-1024x787.png\" alt=\"\" width=\"1020\" height=\"784\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-1024x787.png 1024w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-300x231.png 300w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-768x590.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-1536x1181.png 1536w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230-510x392.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/183b496c-b002-49e6-b1e6-b308cbb04125_1600x1230.png 1600w\" sizes=\"(max-width: 1020px) 100vw, 1020px\" \/><\/div>\n<\/figure>\n<\/div>\n<p>Let\u2019s compare their differences in more detail. The diagram below lists some of the differences.\u00a0<\/p>\n<p>The SOA architectural style offers coarse-grained services, typically a centralized approach where services are grouped by business functions and shared across multiple applications. The microservice style offers fine-grained service granularity through a decentralized approach where small, independent services perform specific functions within an application context.<\/p>\n<p>The communication methods also evolve over time. SOA emphasizes uniform communication protocols and standardized interfaces for services to interact. Microservices lean towards diverse communication protocols and interfaces, often based on REST or message queues.<\/p>\n<p>Cloud computing has evolved from Infrastructure-as-a-Service (IaaS) to Platform-as-a-Service (PaaS) to container-based PaaS. So microservice-based applications deploy on containers by default.<\/p>\n<p>As the technical architecture changes, the organizational structure mirrors it (Conway\u2019s law). So with microservices, the team structure requires multi-functional product teams. Each team focuses on a specific domain.<\/p>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-144 aligncenter\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-754x1024.png\" alt=\"\" width=\"754\" height=\"1024\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-754x1024.png 754w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-221x300.png 221w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-768x1043.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-1131x1536.png 1131w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600-510x693.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/75ede6fa-eb9b-4b27-993e-5210832bac80_1178x1600.png 1178w\" sizes=\"(max-width: 754px) 100vw, 754px\" \/><\/div>\n<\/figure>\n<\/div>\n<h2 class=\"header-with-anchor-widget\">3. What Problems Do Microservices Solve?<\/h2>\n<p>Microservice architecture emerged in the 2010s to solve some key challenges:\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Cloud Computing Needs New Architecture<\/h3>\n<p>Traditional software architectures don\u2019t fully utilize the flexibility cloud computing enables. Containerization technology decomposes hardware resources into smaller units. Orchestration tools easily scale services. So microservices architecture emerged to better leverage these cloud computing advancements.<\/p>\n<h3 class=\"header-with-anchor-widget\">Decouple Services and Teams for Speed<\/h3>\n<p>Monolithic and SOA applications often have tight dependencies among modules, making adaptation to fast-changing business requirements difficult given the internet industry\u2019s explosive growth. Microservices architecture segregates each business domain into a bounded context. Product teams can focus on specific domain requirements. Services and teams communicate via predefined API specifications, facilitating quicker feature delivery and more iterative market testing.<\/p>\n<h3 class=\"header-with-anchor-widget\">Enable Robust Development Methodologies<\/h3>\n<p>A monolithic application failure can bring down the entire application, while microservices are designed to be fault-tolerant. Failures in a single microservice are isolated from other services. Additionally, management tools provide flexible request routing or service downgrade. Chaos engineering, which deliberately injects failures to proactively test vulnerabilities, takes this fault-tolerant design principle to an extreme. DevOps, a set of practices and tools to emphasize collaboration between functions, is a natural fit. These methodology changes allow rapid, reliable product delivery.<\/p>\n<h2 class=\"header-with-anchor-widget\">4. What Challenges Do Microservices Introduce?<\/h2>\n<p>While microservice architecture solves many problems posed by traditional architectures and fits cloud computing\u2019s evolution, it also brings challenges.<\/p>\n<h3 class=\"header-with-anchor-widget\">Operational Overhead<\/h3>\n<p>In a microservices system, it is easy to provision containers, often leading to an explosion of instances. Monitoring and debugging these without proper tooling can be a nightmare.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Increased Complexity<\/h3>\n<p>Microservices architecture encourages segregated domains, so managing service communications and relationships can be complicated. We need to leverage service discovery and configuration management to efficiently manage service instances. This also poses challenges for integration and testing.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Organizational Transformation<\/h3>\n<p>As Conway\u2019s law states, a software architecture shapes the organizational structure. Microservices architecture requires team structured accordingly.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Distributed Transaction<\/h3>\n<p>Data becomes more distributed as each domain has an independent database. While traditional architectures leverage database transactions to ensure data consistency, microservices may need distributed transactions for the same purpose.\u00a0\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Performance Overhead and Challenging Error Handling<\/h3>\n<p>In monolithic applications, different modules communicate via fast in-process function calls. If a failure occurs, the function call gets an immediate response, allowing quick error handling. In contrast, microservices use slower service-to-service network communications, introducing extra latency. Also, microservices typically communicate via RPC. This makes error handling across services less predictable compared to monoliths.<\/p>\n<h2 class=\"header-with-anchor-widget\">5. What Are the Basic Components of Microservices Architecture?<\/h2>\n<p>A typical microservices architecture includes:<\/p>\n<h3 class=\"header-with-anchor-widget\">Load Balancer<\/h3>\n<p>The load balancer sits in front of the API Gateway and distributes incoming requests across multiple API gateway instances. This prevents any single gateway instance from becoming a bottleneck. Common algorithms the load balancer can use to distribute requests include: round robin, sticky sessions, least connections.<\/p>\n<h3 class=\"header-with-anchor-widget\">API Gateway<\/h3>\n<p>The API gateway handles all incoming requests and routes them to the relevant microservices. It communicates with the identity provider to handle authentication and authorization of requests. The gateway leverages the service discovery component to locate the required microservices for a particular requests. Additionally, it can apply filtering rules, policies, and transformations to the requests before routing them to the backend.<\/p>\n<h3 class=\"header-with-anchor-widget\">CDN (Content Delivery Network)<\/h3>\n<p>A CDN (Content Delivery Network) is a group of geographically distributed servers that cache static content in locations closer to end users for faster content delivery. The application first checks the CDN to serve static content. If the content is not in the CDN, the CDN handles the fallback to retrieve that content from the slower backend services.<\/p>\n<h3 class=\"header-with-anchor-widget\">Identity Provider<\/h3>\n<p>An identity provider handles authentication and authorization for users.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Microservices<\/h3>\n<p>Microservices are designed and deployed around specific domains or areas of capability. Each microservice domain has its own database or data store. The API Gateway communicates with the microservices using REST APIs or other protocols. Microservices within the same domain talk to each other via RPC (Remote Procedure Call) for internal interactions.<\/p>\n<h3 class=\"header-with-anchor-widget\">Service Registry and Discovery<\/h3>\n<p>The service registry and discovery component handles the registration and discovery of microservices. As new microservice instances spin up, they register themselves with this service. The API Gateway leverages this component to look up and locate relevant microservices that it needs to route requests to.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Message Queue<\/h3>\n<p>A message queue allows microservices to communicate with each other asynchronously. For example, the payment service may take a long time to complete a payment transaction. In this case, the upstream checkout system can send a request message to a queue such as Kafka and await the response asynchronously instead of blocking. This prevents delays in upstream processes while long-running downstream services finish.<\/p>\n<h3 class=\"header-with-anchor-widget\">Cache<\/h3>\n<p>A cache can be used to store hot data, improving responsiveness for frequent queries. However, when adding caching to microservices architecture, pay careful attention to ensure data consistency between the cache and the underlying databases. Stale, out-of-date cached data could lead to incorrect application behavior.<\/p>\n<h3 class=\"header-with-anchor-widget\">Data Storage: database and object store<\/h3>\n<p>Databases and object stores are used to persist the application&#8217;s data. Different types of databases or data stores can be selected depending on the data model and scalability requirements. For example, in an eCommerce application, a wide-column database like Cassandra might be chosen to store shopping cart items due to its scalability.<\/p>\n<h3 class=\"header-with-anchor-widget\">Configuration Management<\/h3>\n<p>A configuration management system is a centralized system to manage and distribute service configurations.\u00a0<\/p>\n<h3 class=\"header-with-anchor-widget\">Monitoring and Logging<\/h3>\n<p>Observability through monitoring and logging is crucial for maintaining a microservices architecture. Since microservices systems comprise far more service instances than traditional applications, automated monitoring and distributed tracing are important for identifying and debugging problems. Continuous monitoring also enables proactive capacity planning and forecasting to detect bottlenecks.<\/p>\n<h3 class=\"header-with-anchor-widget\">Flow Control<\/h3>\n<p>Flow control tools are sometimes necessary for handling faults in complex microservices systems. These tools help restrict or redirect traffic when issues occur. For example, Hystrix controls interactions between microservices by isolating failing services. Sentinel acts as a circuit breaker to control traffic flow to specific microservices as needed.<\/p>\n<h3 class=\"header-with-anchor-widget\">Service Mesh and Service Orchestration<\/h3>\n<p>A service mesh provides infrastructure for handling communications and control across microservices. It uses a sidecar proxy deployed with each service instance to manage incoming and outgoing traffic flows. This enables capabilities like monitoring and traffic management across services.<\/p>\n<p>Service orchestration focuses on coordinating the sequence and workflow of steps. It leverages the capabilities provided by the service mesh to manage microservice interactions and control workflow execution. Kubernetes, influenced by Google\u2019s Borg cluster manager, is a popular container orchestration system maintained by Cloud Native Computing Foundation (CNCF).<\/p>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-143 aligncenter\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-812x1024.png\" alt=\"\" width=\"812\" height=\"1024\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-812x1024.png 812w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-238x300.png 238w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-768x968.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-1218x1536.png 1218w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600-510x643.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/28a05058-78a6-43c0-8c3f-093d4ad36af6_1269x1600.png 1269w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/div>\n<\/figure>\n<\/div>\n<h2 class=\"header-with-anchor-widget\">6. What Are Some Popular Microservice Solutions?<\/h2>\n<p>The Cloud Native Computing Foundation (CNCF), a Linux Foundation project, was founded in 2015 to help advance\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Operating-system-level_virtualization\" rel=\"\">container technology<\/a>\u00a0and build an ecosystem for cloud computing. The CNCF Cloud Interactive\u00a0<a href=\"https:\/\/landscape.cncf.io\/\" rel=\"\">Landscape<\/a>\u00a0lists tools and their maturity levels. For example, the landscape diagram shows some \u201corchestration &amp; management\u201d tools.<\/p>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><picture><source srcset=\"https:\/\/substackcdn.com\/image\/fetch\/w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534.png 424w, https:\/\/substackcdn.com\/image\/fetch\/w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534.png 848w, https:\/\/substackcdn.com\/image\/fetch\/w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534.png 1272w, https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534.png 1456w\" type=\"image\/webp\" sizes=\"100vw\" \/><\/picture>\n<div><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-148 aligncenter\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-1024x342.png\" alt=\"\" width=\"475\" height=\"159\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-1024x342.png 1024w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-300x100.png 300w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-768x256.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-1536x513.png 1536w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534-510x170.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/0518c58c-e93b-47dd-b713-c90e3e5fc553_1600x534.png 1600w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<p><a href=\"https:\/\/spring.io\/projects\/spring-cloud\" rel=\"\">Spring Cloud<\/a>\u00a0is an out-of-the-box solution that offers a set of integrated tools to create basic microservices components.<\/p>\n<h2 class=\"header-with-anchor-widget\">7. What is a Service Registry?<\/h2>\n<p>A service registry manages service registration and discovery. It has a centralized database to store information about services and their locations. It dispatches client requests to relevant microservice instances.\u00a0<\/p>\n<p>The diagram below illustrates how services register when starting up and shutting down. There are two approaches: self-registration and third-party registration.<\/p>\n<p>In self-registration, services report their status to the service registry, which then updates the registry table. In third-party registration, a service manager handles lifecycles of services by starting and stopping instances and updating the registry. The service manager also pings services to monitor service health.<\/p>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><picture><source srcset=\"https:\/\/substackcdn.com\/image\/fetch\/w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc417b36b-2945-4968-8009-d13b71335f52_1600x792.png 424w, https:\/\/substackcdn.com\/image\/fetch\/w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc417b36b-2945-4968-8009-d13b71335f52_1600x792.png 848w, https:\/\/substackcdn.com\/image\/fetch\/w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc417b36b-2945-4968-8009-d13b71335f52_1600x792.png 1272w, https:\/\/substackcdn.com\/image\/fetch\/w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep\/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc417b36b-2945-4968-8009-d13b71335f52_1600x792.png 1456w\" type=\"image\/webp\" sizes=\"100vw\" \/><\/picture>\n<div class=\"image-link-expand\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-147\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-1024x507.png\" alt=\"\" width=\"1020\" height=\"505\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-1024x507.png 1024w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-300x149.png 300w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-768x380.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-1536x760.png 1536w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792-510x252.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/c417b36b-2945-4968-8009-d13b71335f52_1600x792.png 1600w\" sizes=\"(max-width: 1020px) 100vw, 1020px\" \/><\/div>\n<\/div>\n<\/figure>\n<\/div>\n<p>Let\u2019s look at another important function of the service registry &#8211; service discovery. The diagram below shows two service discovery processes: client-side discovery and server-side discovery.<\/p>\n<p>In client-side discovery, clients first query the service registry for service information. Then they send requests to the API gateway without needing location lookups. In this way, the service discovery function is moved out of the API gateway layer.<\/p>\n<p>In server-side discovery, the API gateway handles locating services. It gets client requests first and redirects them to appropriate services. The API gateway can cache locations to speed up the discovery process. However, this introduces extra complexity to the API gateway in two ways:<\/p>\n<ol>\n<li>\n<p>The API gateway needs to implement service discovery logic.<\/p>\n<\/li>\n<li>\n<p>Keeping its location cache consistent with registry data is challenging.<\/p>\n<\/li>\n<\/ol>\n<div class=\"captioned-image-container\">\n<figure>\n<div class=\"image2-inset\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-146\" src=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-1024x420.png\" alt=\"\" width=\"1020\" height=\"418\" srcset=\"https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-1024x420.png 1024w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-300x123.png 300w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-768x315.png 768w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-1536x630.png 1536w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656-510x209.png 510w, https:\/\/hoclaptrinh.fun\/wp-content\/uploads\/2024\/01\/436aced8-e09a-4b36-b1ba-81b2691fc214_1600x656.png 1600w\" sizes=\"(max-width: 1020px) 100vw, 1020px\" \/><\/div>\n<\/figure>\n<\/div>\n<p>Some examples of service registry products are Netflix Eureka and Hashicorp Consul.<\/p>\n<p>We will cover more microservice interview questions next week. Stay tuned!<\/p>\n\t\t\n<style>\n#text-2578442590 {\n  font-size: 1.2rem;\n}\n<\/style>\n\t<\/div>\n\t\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":145,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,27],"class_list":["post-134","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-interview","tag-microservices"],"_links":{"self":[{"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/posts\/134"}],"collection":[{"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":4,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions\/169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/media\/145"}],"wp:attachment":[{"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoclaptrinh.fun\/index.php\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}