<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kav</title>
    <description>The latest articles on Forem by Kav (@cawizca).</description>
    <link>https://forem.com/cawizca</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F810295%2F4abafbd9-b197-476c-ad89-33d481fa276e.png</url>
      <title>Forem: Kav</title>
      <link>https://forem.com/cawizca</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cawizca"/>
    <language>en</language>
    <item>
      <title>Microservice Communication - Asynchronous communication</title>
      <dc:creator>Kav</dc:creator>
      <pubDate>Wed, 13 Dec 2023 15:47:45 +0000</pubDate>
      <link>https://forem.com/cawizca/microservice-communication-part-02-22mg</link>
      <guid>https://forem.com/cawizca/microservice-communication-part-02-22mg</guid>
      <description>&lt;p&gt;As you remember from my last article, I have been discussing two types of microservice communication mechanisms.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Synchronous communication.&lt;/li&gt;
&lt;li&gt;Asynchronous communication.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We have covered some basic stuff about synchronous communication (what is synchronous communication, best practices, different types of synchronous method so on...). If you didn't read the article I suggest to head over that before reading this by clicking &lt;a href="https://dev.to/cawizca/microservice-communication-part-01-47jk"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So in this article, we will be focusing more on &lt;strong&gt;asynchronous communication&lt;/strong&gt;, the second type of communication mechanism. Let's start with problems of synchronous communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problems with Synchronous communication.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;When we do HTTP calls between multiple services (chain query), &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increase latency with high coupling services. &lt;/li&gt;
&lt;li&gt;Performance, scalability and availability problems.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;To avoid these problems, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce the interservice communication. &lt;/li&gt;
&lt;li&gt;Make microservice communication asynchronous.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Asynchronous communication.
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;In asynchronous communication, client sends the request and it does not wait for the servers response.&lt;/li&gt;
&lt;li&gt;The message brokers handle the message in asynchronous manner.&lt;/li&gt;
&lt;li&gt;The message brokers store the message until consumer consume it.&lt;/li&gt;
&lt;li&gt;If the consumer service is dead, brokers are configured to retry until the successful delivery.&lt;/li&gt;
&lt;li&gt;Messages in the brokers can be persist if it is required, or it could share in memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkph7kymi8cy4lfew3w93.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkph7kymi8cy4lfew3w93.png" alt="Image description" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is one term you should know when we talk about the message brokers. It is &lt;strong&gt;"Events"&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Any action or occurrence in a system, that needs to communicate with the other parts of the system know as an &lt;strong&gt;"Event"&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits Asynchronous communication.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Allows to add and remove subscribers without affecting to producer service.&lt;/li&gt;
&lt;li&gt;Can scale producers, brokers and subscribers independently.&lt;/li&gt;
&lt;li&gt;Event driven architecture is the best way to communicate between microservices by creating and sending events to brokers and subscribing event from brokers.&lt;/li&gt;
&lt;li&gt;If the broker is down when send the message, it can retry for successful delivery.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Types of asynchronous messaging communications.
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. One-to-one(queue) - single receiver - point to point model
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you send 1 request to a specific consumer and the operation will take a long time, it is better to use one-to-one(queue) asynchronous communication.&lt;/li&gt;
&lt;li&gt;One producer and one consumer. Implement as a command pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- RabbitMQ, ActiveMQ, Amazon SQS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  2. One-to-many(topic) - multi receivers - publish/subscribe model
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Producers publish an event and it consumes from zero to multiple microservices by subscribing events on the broker system.&lt;/li&gt;
&lt;li&gt;Publishers don’t need to know any subscribers.&lt;/li&gt;
&lt;li&gt;Events(messages) are available to all subscribers and topics can have more than one subscriber.&lt;/li&gt;
&lt;li&gt;The messages remain persistent in a topic until they are deleted.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- Kafka, RabbitMQ, Amazon SNS and EventBridge.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note : If a client waits for the response, we use Synchronous communication. If the client does not wait for the communication, then we use Asynchronous communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fan-Out Pattern.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This refers the brokers efficiently send messages to all the subscribers.&lt;/li&gt;
&lt;li&gt;Message Fanned out parallelly to multiple destinations. &lt;/li&gt;
&lt;li&gt;In publisher subscriber model, publisher sends the message to the topic, message is immediately fanned out to all subscribers of this topic. &lt;/li&gt;
&lt;li&gt;Each service can operate and scale independently and individually that is completely decoupled and asynchronously. - All components that subscribe to the topic receive every message unless a message filtering policy is set by the subscriber.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Topic-Queue Chaining and Load Balancing Pattern.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mostly related to resilience in microservices and mostly used on serverless architecture. &lt;/li&gt;
&lt;li&gt;Publishers publish the message with fire-and-forget. So it will lose when a microservice is down.&lt;/li&gt;
&lt;li&gt;In the Topic-Queue pattern, we add a queue between the event bus(topic) and each of the subscribers. The queue can act as a buffering load balancer. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note:- with using Kafka, you don't need to use an additional queue mechanism. Because, Kafka can already persist messages into clusters. When the subscribers are up and running they can consume messages that they subscribed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Through this article, I have discussed about some of the theoretical concepts of asynchronous communication. We will discuss how to build an application with asynchronous communication (like Kafka) with our future articles. So make sure to follows, if you don't need to miss any of article. Lets meet again with another article. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Microservice communication - Synchronous communication</title>
      <dc:creator>Kav</dc:creator>
      <pubDate>Thu, 07 Dec 2023 15:45:35 +0000</pubDate>
      <link>https://forem.com/cawizca/microservice-communication-part-01-47jk</link>
      <guid>https://forem.com/cawizca/microservice-communication-part-01-47jk</guid>
      <description>&lt;p&gt;As you know, in the microservice architecture, each service is isolated from other services. To communicate from one service to one or more other services, we need to know about the communication mechanisms. In this article series, we will discuss about most common microservice communication mechanisms. Lets start our learning journey.&lt;/p&gt;

&lt;p&gt;Microservice communication mechanisms can be divided into two categories.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Synchronous communication&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client service sends the request to one or more services and wait for the response(s) from that services.&lt;/li&gt;
&lt;li&gt;Use HTTP(HTTPS as well), gRPC protocols for communication.&lt;/li&gt;
&lt;li&gt;Client blocks the thread. When it receives the response the rest of the code will continue.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Asynchronous communication&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client service sends the request to one or more services and it does not wait for the response(s) from that services.&lt;/li&gt;
&lt;li&gt;Use AMQP protocol. &lt;/li&gt;
&lt;li&gt;Using AMQP protocol clients send the message with help of message broker systems like Kafka, RabbitMQ.&lt;/li&gt;
&lt;li&gt;Messages consume from subscriber systems in async way and it does not wait for quick response.&lt;/li&gt;
&lt;li&gt;AC can be divided into 2 categories.

&lt;ul&gt;
&lt;li&gt;One to One (Queue)&lt;/li&gt;
&lt;li&gt;One to Many (Topic)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this part, we will be more focused on synchronous communication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Different types of communication patterns.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Request/Response communication.&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; When service A sends a request to service B, service A always wait for service Bs response.&lt;/li&gt;
&lt;li&gt;For synchronous request/response communication - use HTTP and REST protocols&lt;/li&gt;
&lt;li&gt;Uses to expose APIs from microservices.&lt;/li&gt;
&lt;li&gt;If the communication between internal microservicers - use gRPC protocol. gRPC provides high performance and low latency.&lt;/li&gt;
&lt;li&gt;If you need to define the structure of data - use GraphQL. - &lt;/li&gt;
&lt;li&gt;GraphQL provides 1 response per request in a more flexible and efficient way.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- REST communications, GraphQL, gRPC etc...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Pull communication.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A service request data from another service only when it needs. This is also know as polling.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- An Order processing service pull current product data from inventory service to check the availability. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Based on HTTP, AMQP (short polling - long polling)&lt;/li&gt;
&lt;li&gt;It’s a call-and-ask model. (also called “Polling”)&lt;/li&gt;
&lt;li&gt;It is basically the same as refreshing your email every 5 minutes to check for new mail.&lt;/li&gt;
&lt;li&gt;Drawback. 

&lt;ul&gt;
&lt;li&gt;waste of bandwidth (if there is no new mail and a response comes from the server.)&lt;/li&gt;
&lt;li&gt;Opening and closing connections is expensive. The model does not scale well.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Generally, we can poll an API at any time. But some applications limit API calls.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Polling can be divided into two categories.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Short polling - In short polling, the client sends requests frequently to the server to check for new update or data. Server responses to the each request even there is no any updates.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- Real-time dashboards, servers' health checks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Long polling - The client send one request and server holds it until new data is arrived.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- Notification service&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Push communication.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A service keep sends data to another service without asking it.&lt;/li&gt;
&lt;li&gt;Based on the HTTP, Websocket protocol.&lt;/li&gt;
&lt;li&gt;Use for real-time two-way one-to-many communication like chat applications.&lt;/li&gt;
&lt;li&gt;Here, clients and servers can both send messages to each other at any time.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ex:- A user service push updates to an email service to trigger email about user updates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Event driven communication.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Asynchronous messaging pattern that use publishers and subscribers.&lt;/li&gt;
&lt;li&gt;These microservices don’t call each other. They create and consume events in an async way through a message broker system (RabbitMQ and Kafka queues).&lt;/li&gt;
&lt;li&gt;Use Publish/Subscribe pattern.
Benefits

&lt;ul&gt;
&lt;li&gt;Producer service does not know about its consumer service. Consumer services don't necessarily know about the producer. So, services can be deployed independently. So it’s a loosely coupled microservice.
Drawbacks &lt;/li&gt;
&lt;li&gt;No clear central place or orchestrator; this increases the complexity of architecture.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Synchronous communication.
&lt;/h2&gt;

&lt;p&gt;As I briefly explained above, when a service communicate with another service by requesting some data and it waits for the response (with requested data), it is a synchronous communication.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Lets take user login scenario as an example. First a user send a request with his email and password. Then client application sends these data to backend service and wait until its acknowledgement. If those input are valid user can log in.&lt;br&gt;
This is a REST based communication mechanism. There are more synchronous communication ways that we will discuss in this article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;These microservices don’t call each other. They create and consume events in an async way through a message broker system (RabbitMQ and Kafka queues).&lt;/li&gt;
&lt;li&gt;Use Publish/Subscribe pattern.&lt;/li&gt;
&lt;li&gt;Benefits

&lt;ul&gt;
&lt;li&gt;Producer service does not know about its consumer service. Consumer services don't necessarily know about the producer. So, services can be deployed independently. So it’s a loosely coupled microservice.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Drawbacks 

&lt;ul&gt;
&lt;li&gt;No clear central place or orchestrator; this increases the complexity of architecture.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Synchronous communication and best practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In synchronous communication, clients send a request and wait for a response.&lt;/li&gt;
&lt;li&gt;Communication protocols can be HTTP or HTTPS.
should follow the HTTP/REST protocol (can be extended with gRPC and GraphQL).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Different types of synchronous communication methods
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In this section, I will be discussing briefly some popular synchronous communication methods.&lt;/li&gt;
&lt;li&gt;I will discuss each of this method deathly in my future articles.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1. RESTful applications.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Applications that use HTTP/REST for communication.&lt;/li&gt;
&lt;li&gt;There are some rules to define RESTful APIs as below.&lt;/li&gt;
&lt;li&gt;You can refer &lt;a class="mentioned-user" href="https://dev.to/ksound22"&gt;@ksound22&lt;/a&gt; &lt;a href="https://www.freecodecamp.org/news/rest-api-best-practices-rest-endpoint-design-examples/"&gt;REST API Best Practices – REST Endpoint Design Examples&lt;/a&gt; for better patterns.&lt;/li&gt;
&lt;li&gt;Benefits

&lt;ul&gt;
&lt;li&gt;Requests can simply be sent using browsers.&lt;/li&gt;
&lt;li&gt;HTTP protocol&lt;/li&gt;
&lt;li&gt;HTTP GET has organic (built-in) caching options.&lt;/li&gt;
&lt;li&gt;JSON representative request-responses&lt;/li&gt;
&lt;li&gt;Provide better scalability.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Drawbacks

&lt;ul&gt;
&lt;li&gt;Send multiple requests to get relational data.&lt;/li&gt;
&lt;li&gt;Chatty communication when enriching data.&lt;/li&gt;
&lt;li&gt;Over-fetching (providing additional information that is not required) and under-fetching requests are hard to implement and require multiple calls.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. GraphQL
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;It is a query and manipulation language. It allows us to define the structure of the required data.&lt;/li&gt;
&lt;li&gt;It provides access to many sources with a single request. So it reduces the number of multiple network calls.&lt;/li&gt;
&lt;li&gt;Core concepts

&lt;ul&gt;
&lt;li&gt;Schemas - Describe all the possible data that clients can query on it.&lt;/li&gt;
&lt;li&gt;Resolvers - Those are the functions that attach to fields in a schema. During executions, resolvers call to produce the values.&lt;/li&gt;
&lt;li&gt;Mutation - GraphQL operations (allowing the insert of new data and modification of existing data)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Benefits&lt;/li&gt;
&lt;li&gt;Can get exactly what you need.&lt;/li&gt;
&lt;li&gt;Can get many resources in a single request.&lt;/li&gt;
&lt;li&gt;Evolve APIs without versioning.&lt;/li&gt;
&lt;li&gt;Fast and quick response time (because it reduces the number of calls to get data)&lt;/li&gt;
&lt;li&gt;Strongly typed (define types before querying). It reduces miscommunication.)&lt;/li&gt;
&lt;li&gt;More flexible with schema and type systems&lt;/li&gt;
&lt;li&gt;Drawbacks

&lt;ul&gt;
&lt;li&gt;Query complexity. When accessing multiple fields in a single query, it may request too much-nested field data at a time. This causes performance problems)&lt;/li&gt;
&lt;li&gt;Caching (complicated to implement a simple cache in GQL when compared to REST)&lt;/li&gt;
&lt;li&gt;Rate Limit. (It is difficult to allow a specific number of requests at a specific time.)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Issues with both REST and GraphQL&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network performance issues affect inter-service communication.&lt;/li&gt;
&lt;li&gt;Backend communication performance requirements&lt;/li&gt;
&lt;li&gt;Real-time communication requirements&lt;/li&gt;
&lt;li&gt;Streaming requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. gRPC - Google Remote Procedure Calls
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;There are two kinds of APIs.&lt;/li&gt;
&lt;li&gt;Public APIs - User HTTP REST. APIs should be human-readable.&lt;/li&gt;
&lt;li&gt;Backend APIs - Use gRPC. The Importance of backend APIs is network performance instead of human readability.&lt;/li&gt;
&lt;li&gt;gRPC is used to communicate between services, efficiently and independently in their preferred languages.&lt;/li&gt;
&lt;li&gt;Focused on high performance. For that, it uses the HTTP/2 protocol to transport binary messages.

&lt;ul&gt;
&lt;li&gt;HTTP/1 opens HTTP calls for a request. (HTTP/2 provides long lasting connection)&lt;/li&gt;
&lt;li&gt;HTTP/1.1 does not compress headers. (HTTP/2 compresses the headers and data to the binary format.)&lt;/li&gt;
&lt;li&gt;Only accept request response patterns.(HTTP/2 support server push. That means the client can send multiple messages from one request to the server. - streaming) - Less chatter
EX:- In HTTP/1.1 Clients have to send 3 requests to access 3 assets and have to get three responses from that request. In &lt;/li&gt;
&lt;li&gt;HTTP/2 clients can send requests inside one TCP connection and wait for one response from the server.&lt;/li&gt;
&lt;li&gt;HTTP/2 supports multiplexing ( Server and client send multiple messages in parallel over the same TCP connection.)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;It uses Protocol Buffers (Protobuf) for service-to-service communication.&lt;/li&gt;
&lt;li&gt;Messages are smaller than JSON.&lt;/li&gt;
&lt;li&gt;Passing JSON is more CPU intensive. (Because the format is human readable.) &lt;/li&gt;
&lt;li&gt;Protobuf provides more security than JSON because it’s not human readable, easy to install SSL for client and server.&lt;/li&gt;
&lt;li&gt;Benefits

&lt;ul&gt;
&lt;li&gt;Provide 30-40% more performance when compared to REST because of HTTP/2 protocol.&lt;/li&gt;
&lt;li&gt;gRPC uses binary serialization, which also provides higher Performance and less bandwidth compared to JSON.&lt;/li&gt;
&lt;li&gt;Support multiple languages and platforms.&lt;/li&gt;
&lt;li&gt;Support for bi-directional streaming.&lt;/li&gt;
&lt;li&gt;Support SSL/TLS usage.&lt;/li&gt;
&lt;li&gt;Support many authentication methods.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Usages

&lt;ul&gt;
&lt;li&gt;Synchronous microservice to microservice communication.
Polyglot environments that need to support mixed programming languages.&lt;/li&gt;
&lt;li&gt;Low latency and high throughput communication where performance is critical.&lt;/li&gt;
&lt;li&gt;Point-to-point real-time communication. (push messages in real-time and are required to support bi-directional streaming.)&lt;/li&gt;
&lt;li&gt;The network-constrained environment requires less bandwidth usage. (Binary gRPC messages are always smaller than text-based JSON)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. WebSocket (ws:// , wss://)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A websocket uses for real-time two way communications between client and server. (Ex:- chat with an agent.)&lt;/li&gt;
&lt;li&gt;Send messages to the server and receive event based communication without having polling.&lt;/li&gt;
&lt;li&gt;Provide bidirectional protocol for same client server communications.&lt;/li&gt;
&lt;li&gt;Stateful protocol - Until terminating the connection from one party, communication stays alive.&lt;/li&gt;
&lt;li&gt;Use Cases

&lt;ul&gt;
&lt;li&gt;For real-time application development. (Stock market/ Crypto currency prices changing)&lt;/li&gt;
&lt;li&gt;Online gaming applications&lt;/li&gt;
&lt;li&gt;Chat applications&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  5. Webhooks
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;For the simple understand, a webhook is just a POST request that is used to push messages/events between two services.&lt;/li&gt;
&lt;li&gt;Uses HTTP protocol to communicate with applications.&lt;/li&gt;
&lt;li&gt;Usages

&lt;ul&gt;
&lt;li&gt;Get real-time notifications/data from external services.&lt;/li&gt;
&lt;li&gt;To trigger scheduled actions.&lt;/li&gt;
&lt;li&gt;Sync data between different systems.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Benefits

&lt;ul&gt;
&lt;li&gt;Best way to get real-time updates.&lt;/li&gt;
&lt;li&gt;Easy to integrate with an application.&lt;/li&gt;
&lt;li&gt;Efficient and reduce the latency.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Drawback

&lt;ul&gt;
&lt;li&gt;Issue with delivery reliability&lt;/li&gt;
&lt;li&gt;Security issue (Can be affect to DDOS easily)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, through this article, I have discussed what the microservice communication methods are and what the synchronous communication patterns are. If you have any questions regarding this article please let me know by commenting. I will hope to discuss synchronous communication more deeply in the upcoming articles. So stay tuned with me.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Why are API gateways so damn important?🤔</title>
      <dc:creator>Kav</dc:creator>
      <pubDate>Wed, 22 Nov 2023 17:27:52 +0000</pubDate>
      <link>https://forem.com/cawizca/why-are-api-gateways-so-damn-important-23ng</link>
      <guid>https://forem.com/cawizca/why-are-api-gateways-so-damn-important-23ng</guid>
      <description>&lt;p&gt;You may heard about &lt;strong&gt;"API Gateway"&lt;/strong&gt; term somewhere in your software engineering journey. &lt;br&gt;
You probably should've Googled and learned that back then, or probably not. I guess that concept was kinda tricky for you, even though it's pretty basic. &lt;br&gt;
Hope this article helps you pick up some new knowledge or brush up on what you already know. Let's dive into this 🙌.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the heck is this API gateway thing?
&lt;/h2&gt;

&lt;p&gt;Okay, calm down. If you are total noob here, just forget the word "API" for now. You all know what is a gate, yeah? Think of this whole API gateway situation as your old gate.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/8bX8xnLxFs3h6/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/8bX8xnLxFs3h6/giphy-downsized-large.gif" width="576" height="432"&gt;&lt;/a&gt;&lt;br&gt;
What does this gate actually do? It's like the entry point to your property, and separates your stuff from everybody else's, yeah?&lt;br&gt;
That's what these API gateway things are doing too. It acts as a single entry point to all the APIs. It uses to separate client APIs from internal services(microservices).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bI1AVIJc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4mcjiym6i31g4cq1jwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bI1AVIJc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4mcjiym6i31g4cq1jwa.png" alt="How API gateway works" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What's the point of using these API gateways anyway?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Handling cross-cutting concerns.&lt;/strong&gt;&lt;br&gt;
Let me take a guess, you have no idea what this "cross-cutting concerns" means, yeah? Just think of it as like the common stuff that every API endpoint needs, like authentication, authorization, rate limiting, caching etc...&lt;br&gt;
Let me explain what are the benefits of using API gateway for cross cutting concerns.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduce the duplications&lt;/strong&gt; - Let's use authorization as an example. If we don't have an API gateway, we need to duplicate the authorization implementation in every microservice. And that means a bunch of duplicate codes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduce the inconsistent implementations&lt;/strong&gt; - Different engineering teams may work on each (different) microservice and their implementations differently from each other. With an API gateway though, we can reduce that mess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduce the code complexity&lt;/strong&gt; - So having less duplicate code and keeping things consistent makes the overall code way easier to understand.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Decouples the client applications from the internal microservices.&lt;/strong&gt;&lt;br&gt;
Microservice architectures consist with set of little services. Without an API gateway, we would need to call each service directly. So if anything changes, we have to change the client app code too.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For an example, let's assume we deploy our application on AWS Beanstalk or EC2. If we move the app to another Beanstalk or EC2, we would need to update the client endpoint too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But with an API gateway, we don't need to mess with the client code. It just maps the external APIs to the new internal services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Aggregate data from different services to a single response.&lt;/strong&gt;&lt;br&gt;
I think you got the idea. Let's imagine a client requests some data from the server. They would typically need to navigate multiple microservices to gather the full data required (You can think this as something like database query concept). In these types of situations, an API gateway can aggregate the necessary information from the various services, and deliver it to the client as a single response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Request sharping.&lt;/strong&gt;&lt;br&gt;
Okay, what is this request sharping doing? It helps to optimize backend performance by managing amount of requests received. We can take some examples like rate limiting, caching, queueing for this. (we will discuss more about these features in our future articles.)&lt;/p&gt;

&lt;h2&gt;
  
  
  API gateway patterns.
&lt;/h2&gt;

&lt;p&gt;I'm going to discuss about 3 most popular gateway patterns in briefly through this article. We will be discussing more details about these patterns in our upcoming articles and projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Gateway Routing Pattern.&lt;/strong&gt;&lt;br&gt;
Gateway routing pattern routes incoming API requests to the relevant microservice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Gateway Aggregation Pattern.&lt;/strong&gt;&lt;br&gt;
API gateway aggregate data from multiple microservices into single response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Gateway Offloading Pattern.&lt;/strong&gt;&lt;br&gt;
API gateway handle cross cutting concerns before passing the requests to the relevant microservice.&lt;/p&gt;

&lt;p&gt;Alright, at this point I’d like to explore some useful applications of API gateways.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Backend for Frontend Pattern.&lt;/strong&gt;&lt;br&gt;
Here we use separate API gateways for specific client applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For an example, One API gateway for web client, another API gateway for mobile client so on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Service Aggregator Pattern.&lt;/strong&gt;&lt;br&gt;
Here what this does, when API gateway receives requests from the clients, dispatch the request of multiple internal backend services, combine the results and responds back to the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Service Registry and Discovery Pattern.&lt;/strong&gt;&lt;br&gt;
This allows to find the network locations of microservices without injecting or coupling. Service registry uses to update service locations. Using service discovery pattern, client find network locations of relevant microservices.&lt;/p&gt;

&lt;p&gt;That covers the main points of API gateway I wanted to share through this article. If you're new to these concepts, hopefully this article has helped sharp your knowledge. Feel free to drop any questions in the comments. Look forward to connecting again in a future article with you all!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
