<?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: Vijaykumar Ponnusamy</title>
    <description>The latest articles on Forem by Vijaykumar Ponnusamy (@vijayponnusamy1990).</description>
    <link>https://forem.com/vijayponnusamy1990</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%2F632747%2F932e99a6-05a4-4090-8029-db2151e3c3cd.png</url>
      <title>Forem: Vijaykumar Ponnusamy</title>
      <link>https://forem.com/vijayponnusamy1990</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vijayponnusamy1990"/>
    <language>en</language>
    <item>
      <title>Outbox design pattern</title>
      <dc:creator>Vijaykumar Ponnusamy</dc:creator>
      <pubDate>Sat, 14 Sep 2024 15:40:29 +0000</pubDate>
      <link>https://forem.com/vijayponnusamy1990/outbox-design-pattern-3080</link>
      <guid>https://forem.com/vijayponnusamy1990/outbox-design-pattern-3080</guid>
      <description>&lt;p&gt;When working with microservices architecture, a common use case involves ensuring consistency between databases and messaging systems. This often arises when you need to both update a database and publish an event, or vice versa. For instance, you might want to write data to a database and simultaneously notify other services by publishing an event.&lt;/p&gt;

&lt;p&gt;While two-phase commit (2PC) can be used to maintain consistency across multiple systems within a single database, it's not suitable for ensuring consistency between a database and a messaging system. &lt;/p&gt;

&lt;p&gt;Another challenge in microservices architectures is maintaining event order when your application is distributed across multiple pods. Ensuring that events are processed in the correct sequence can be difficult, especially when dealing with distributed systems.&lt;/p&gt;

&lt;p&gt;The outbox design pattern offers a practical solution to these challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the outbox design pattern?
&lt;/h2&gt;

&lt;p&gt;The outbox design pattern decouples database updates from message publication. To implement this pattern, a new table, known as the outbox table, is introduced to store events awaiting delivery to a message broker. When a service needs to update its database and publish a corresponding event, it creates a local transaction to modify both the main table and the outbox table&lt;/p&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%2F68yxu4a6h9x5sds4v6re.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%2F68yxu4a6h9x5sds4v6re.png" alt="OutboxDesignPattern" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CustomerService:&lt;/strong&gt; This represents the microservice responsible for handling customer data. It interacts with both the Customer table in the Customer DB and the CustomerOutbox table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customer DB:&lt;/strong&gt; This is the database where the main customer data is stored. It contains the Customer table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CustomerOutbox:&lt;/strong&gt; This is the outbox table, a dedicated table for storing messages that need to be published to a message broker. It serves as a temporary holding area for events that have been created but not yet delivered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Outbox Scheduler:&lt;/strong&gt; This is a component responsible for periodically scanning the CustomerOutbox table and delivering pending messages to the message broker. It acts as a background task or service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Broker:&lt;/strong&gt; This represents the message broker, such as Kafka or RabbitMQ, where the published events are sent. It receives messages from the Outbox Scheduler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Data Consistency:&lt;/strong&gt; Ensures that database updates and message publication are atomic, preventing inconsistencies.&lt;br&gt;
&lt;strong&gt;Reliability:&lt;/strong&gt; Reduces the risk of message loss due to failures in the messaging system.&lt;br&gt;
&lt;strong&gt;Decoupling:&lt;/strong&gt; Separates message production from delivery, improving system resilience.&lt;br&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; Allows for different message delivery mechanisms without affecting the core business logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Increased Complexity:&lt;/strong&gt; Introducing an additional table and a dedicated process can make your system more complex to manage and understand.&lt;br&gt;
&lt;strong&gt;Potential Performance Overhead:&lt;/strong&gt; The outbox table and message delivery process can introduce overhead, especially in high-traffic scenarios.&lt;br&gt;
&lt;strong&gt;Scalability Challenges:&lt;/strong&gt; As the volume of messages increases, the outbox table and message delivery process may become bottlenecks.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>designpatterns</category>
    </item>
    <item>
      <title>Authentications methods for REST APIs</title>
      <dc:creator>Vijaykumar Ponnusamy</dc:creator>
      <pubDate>Thu, 12 Sep 2024 15:05:41 +0000</pubDate>
      <link>https://forem.com/vijayponnusamy1990/authentications-methods-for-rest-apis-42p2</link>
      <guid>https://forem.com/vijayponnusamy1990/authentications-methods-for-rest-apis-42p2</guid>
      <description>&lt;p&gt;There are several authentication methods commonly used in REST APIs to make them secure. The most common methods are,&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Authentication
&lt;/h2&gt;

&lt;p&gt;This is the simplest form of authentication. The client sends a username and password in headers when they make an API call to the server. The server validates the credentials and responds to the client. This is not very secure unless used over the HTTPS protocol.&lt;/p&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%2Frl4lb8gmwxl0c8jhp6bt.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%2Frl4lb8gmwxl0c8jhp6bt.png" alt="Basic Authentication" width="800" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  API Key Authentication
&lt;/h2&gt;

&lt;p&gt;The client must register with the server to obtain an API key. The client then includes this API key in their requests to the server. The server validates the API key and responds accordingly. While this method is simple to implement, it is not secure if the API key is exposed. Additionally, the server must maintain the API key for each client. It requires storage for that.&lt;/p&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%2Fsmizgq3imh8zuhsggscy.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%2Fsmizgq3imh8zuhsggscy.png" alt="API Key Authentication" width="800" height="675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Token Based Authentication
&lt;/h2&gt;

&lt;p&gt;The client must authenticate by sending a username, password, or API key in the header. The server validates these credentials, generates a token ( often a JWT), and sends it back to the client. The client then uses this token in subsequent requests to the server to access resources. This method is more secure than using API keys or Basic authentication. &lt;/p&gt;

&lt;p&gt;The server does not store anything in this approach, as the JWT token contains the user and access grant details.&lt;/p&gt;

&lt;p&gt;A JSON Web Token (JWT) is an open standard that enables secure communication between two parties. Data is verified with a digital signature, and encryption ensures security when sent via HTTP.&lt;/p&gt;

&lt;p&gt;JWTs have three key components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header:&lt;/strong&gt; Specifies the token type and the signing algorithm.&lt;br&gt;
&lt;strong&gt;Payload:&lt;/strong&gt; Contains information about the token issuer, expiration, and other claims.&lt;br&gt;
&lt;strong&gt;Signature:&lt;/strong&gt; Ensures the message hasn’t been altered during transit with a secure signature.&lt;/p&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%2F1nd43yhxc3eouj0cgwsb.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%2F1nd43yhxc3eouj0cgwsb.png" alt="JWT Token Authentication" width="800" height="657"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Session Based Authentication
&lt;/h2&gt;

&lt;p&gt;The client sends an authentication request, providing their username and password. Upon successful authentication, the server generates a unique session identifier (session ID) and stores it in its session store. The server then responds to the client with the session ID.&lt;/p&gt;

&lt;p&gt;In subsequent requests, the client includes the session ID in the request headers. The server validates the session ID against its session store to verify the user's identity. If the validation is successful, the server processes the request and responds with the requested data.&lt;/p&gt;

&lt;p&gt;Session-based authentication differs from JWT authentication in several key aspects:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stateful:&lt;/strong&gt; Session-based authentication is stateful, requiring the server to maintain session information for each user. This can make it less secure and less scalable compared to JWTs.&lt;br&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Session-based authentication can be less secure than JWTs if not implemented properly, as session IDs can be stolen or hijacked.&lt;br&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Session-based authentication can be challenging to scale as it requires session synchronization across multiple servers.&lt;br&gt;
On the other hand, JWT authentication is stateless, more secure, and scalable.&lt;/p&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%2F2wx4ljeijc6hqjtacvz6.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%2F2wx4ljeijc6hqjtacvz6.png" alt="Session Based Authentication" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading my blog! I'd love to hear your thoughts. Please share your comments below.&lt;/p&gt;

</description>
      <category>security</category>
      <category>rest</category>
    </item>
  </channel>
</rss>
