<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Anurag Jain]]></title><description><![CDATA[Software Engineer by ❤️]]></description><link>https://blog.anuragjain.me</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 10:08:46 GMT</lastBuildDate><atom:link href="https://blog.anuragjain.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding Forward & Reverse Proxy and NAT]]></title><description><![CDATA[You must have heard about these three terms. The motivations that drove me to write this blog are as follows:

These are very important and are used everywhere for scaling and security.

We generally get confused between reverse and forward proxies.
...]]></description><link>https://blog.anuragjain.me/understanding-forward-reverse-proxy-and-nat</link><guid isPermaLink="true">https://blog.anuragjain.me/understanding-forward-reverse-proxy-and-nat</guid><category><![CDATA[networking]]></category><category><![CDATA[Reverse Proxy]]></category><category><![CDATA[forward-proxy]]></category><category><![CDATA[nat]]></category><dc:creator><![CDATA[Anurag Jain]]></dc:creator><pubDate>Sat, 16 Mar 2024 06:50:44 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1710572385083/b3f66413-f325-45b2-b350-351b35d2808b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You must have heard about these three terms. The motivations that drove me to write this blog are as follows:</p>
<ul>
<li><p>These are very important and are used everywhere for scaling and security.</p>
</li>
<li><p>We generally get confused between reverse and forward proxies.</p>
</li>
</ul>
<h2 id="heading-reverse-proxy">Reverse Proxy</h2>
<p>In simpler words - It sits between the internet and servers. So when someone outside (like a user browsing a website) wants to access a server, they first communicate with the reverse proxy, which then forwards their request to the appropriate server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710565830137/3670cd3f-be59-4c4d-a130-2252ab66786c.png" alt class="image--center mx-auto" /></p>
<p>Eg. Think of a reverse proxy like a waiter in a busy restaurant. Instead of customers going to the kitchen to order food, they tell the waiter what they want, and the waiter takes their order to the kitchen for them. Similarly, a reverse proxy sits between people using a website (like customers in a restaurant) and the servers where the website is stored (like the kitchen), taking requests from users and passing them on to the servers.</p>
<h3 id="heading-advantages"><strong>Advantages</strong></h3>
<ol>
<li><p><strong>Load Balancing:</strong> As you can see in diagram Reverse Proxy can help in distributing traffic across multiple servers.</p>
</li>
<li><p><strong>Security:</strong> Reverse proxy can inspect the request and can help in Filtering out the malicious traffic or enforcing security policies.</p>
</li>
<li><p><strong>Cache:</strong> Frequently requested content can be cached by reverse proxy which helps in reducing the load at server.</p>
</li>
<li><p><strong>SSL:</strong> At servers you don't need to understand the https that can be done at reverse proxy itself.</p>
</li>
</ol>
<p>Nginx is one of the popular proxy server. Eg. with nginx</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710565560787/2d302abd-1231-4a93-a426-493dd92aed71.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-forward-proxy">Forward Proxy</h2>
<p>In simpler words - It sits between the client and the internet. When a client wants to access something on the internet, they communicate with the forward proxy first, which then fetches the requested information from the internet on behalf of the client.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1710566127762/fdab6d10-121d-451f-8553-f39336875f67.png" alt class="image--center mx-auto" /></p>
<p>Eg. In the days before direct dialing, telephone operators played a crucial role in connecting calls. When someone wanted to make a call, they would speak to the operator, who would then connect them to the desired number. The operator acted as a forward proxy, facilitating communication between callers and ensuring that calls reached their intended recipients.</p>
<h3 id="heading-advantages-1"><strong>Advantages</strong></h3>
<p><strong>Anonymity:</strong> They can mask the IP addresses of clients, providing anonymity when accessing online resources.</p>
<p><strong>Content Filtering:</strong> Forward proxies can block or filter specific types of content, such as malicious websites or inappropriate material, based on predefined policies.</p>
<p><strong>Caching:</strong> Similar to reverse proxies, forward proxies can cache frequently requested content, reducing bandwidth usage and speeding up subsequent requests.</p>
<p><strong>Access Control:</strong> They enable organizations to enforce access policies, restricting access to certain websites or services based on user credentials or permissions.</p>
<p>Squid is one of the popular forward proxy server.</p>
<h2 id="heading-network-address-translation-nat">Network Address Translation (NAT)</h2>
<p>Lastly let's talk about NAT. Basically every device connected to a network requires a unique identifier to facilitate communication. NAT serves as the bridge between private internal networks and the public internet by translating between private IP addresses used within a local network and public IP addresses used on the internet.</p>
<p>NAT performs two primary functions:</p>
<ol>
<li><p><strong>Internet Access for Private Networks</strong>: NAT enables devices within a private network to access resources on the Internet. Devices within the private network are assigned private IP addresses, and the NAT device translates these private IP addresses to a single public IP address when communicating with external servers or services on the Internet.</p>
</li>
<li><p><strong>Security</strong>: NAT provides a level of security by hiding the internal IP addresses of devices within the private network from external sources. When devices initiate connections to external servers or services, the external entities only see the public IP address assigned by the NAT device, helping to obscure the topology of the internal network and mitigate certain types of attacks.</p>
</li>
<li><p><strong>Load Balancing</strong>: NAT can be used for load balancing traffic across multiple internal servers or services. In this scenario, incoming requests to a single public IP address are distributed across a pool of internal servers using different private IP addresses, based on predefined rules or algorithms.</p>
</li>
<li><p><strong>IPv4 to IPv6 Translation</strong></p>
</li>
</ol>
<p>Forward Proxy and NAT (Network Address Translation) serve similar purposes in networking, but they operate at different layers of the OSI model and offer distinct functionalities.</p>
<p><img src="https://upload.wikimedia.org/wikipedia/commons/c/c7/NAT_Concept-en.svg" alt class="image--center mx-auto" /></p>
<p>I hope this is useful.</p>
]]></content:encoded></item><item><title><![CDATA[DNS - End to End Understanding]]></title><description><![CDATA[In this blog post, I will discuss how to set up the connection between your domain and server. I will also try to explain what happens behind the scenes when you visit example.com, and how exactly your web browser finds the correct server to display ...]]></description><link>https://blog.anuragjain.me/dns-end-to-end-understanding</link><guid isPermaLink="true">https://blog.anuragjain.me/dns-end-to-end-understanding</guid><category><![CDATA[domain]]></category><category><![CDATA[dns]]></category><category><![CDATA[dns resolver]]></category><category><![CDATA[dns-records]]></category><category><![CDATA[understanding dns]]></category><dc:creator><![CDATA[Anurag Jain]]></dc:creator><pubDate>Sat, 18 Mar 2023 11:18:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/gyIRjKPXupE/upload/59fd0fb63584b128670ac2fe1920ec1f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog post, I will discuss how to set up the connection between your domain and server. I will also try to explain what happens behind the scenes when you visit <a target="_blank" href="http://example.com">example.com</a>, and how exactly your web browser finds the correct server to display the website.</p>
<p>Suppose you have purchased the domain "<a target="_blank" href="http://example.com">example.com</a>" from a domain provider. How can you configure it so that when someone visits <a target="_blank" href="http://example.com">example.com</a>, it will reach your server?</p>
<p><strong><em>You need to configure the DNS records.</em></strong></p>
<h2 id="heading-dns-records">DNS Records</h2>
<p>What are DNS Records? - <a target="_blank" href="https://www.cloudflare.com/en-in/learning/dns/dns-records/">https://www.cloudflare.com/en-in/learning/dns/dns-records/</a> - DNS records are instructions that live in authoritative DNS servers and provide information about a domain including what IP address is associated with that domain and how to handle requests for that domain.</p>
<h3 id="heading-a-record-aaaa-record">A Record / AAAA record</h3>
<p>A Record - it's a mapping of the domain to the server's IPV4 address</p>
<p>AAAA Record - it's a mapping of the domain to the server's IPV6 address</p>
<p><em>1) Can I have multiple A-record for the same domain?</em></p>
<p>Yes, you can. It is called round-robin DNS, and the browser just chooses one of them randomly. It is a well-used method of getting cheap load balancing, but it has cons as well - i.e. one host goes down, users will still try to access it.</p>
<p><em>2) Can we point different IP Addresses to subdomains (www.example.com, blogs.example.com, labs.example.com) as well?</em></p>
<p>Yes, You can point the subdomain like www, labs etc. to a different IP address.</p>
<h3 id="heading-cname">CNAME</h3>
<p>A DNS CNAME record provides an alias for another domain. Here are the examples where it can help you</p>
<p>1) if Each subdomain points to the same server then you have two choices either write A record for each subdomain or set CNAME which points to the main domain</p>
<ul>
<li><p><a target="_blank" href="http://www.example.com">www.example.com</a> → <a target="_blank" href="http://example.com">example.com</a></p>
</li>
<li><p><a target="_blank" href="http://labs.example.com">labs.example.com</a> → <a target="_blank" href="http://example.com">example.com</a></p>
</li>
</ul>
<p>The second approach is better to approach - let's say the server IP changes you don’t need to change anything other than A record i.e. <a target="_blank" href="http://example.com">example.com</a> → 13.203.30.40</p>
<p>2) CNAME record also helps you in redirecting your page to some other website <a target="_blank" href="http://status.example.com">status.example.com</a> → <a target="_blank" href="http://example.pageduty.com">example.pageduty.com</a></p>
<h3 id="heading-ns-record">NS Record</h3>
<p>Nameserver is the server that stores A, AAAA, and CNAME records for your domain. NS Record helps you set up the right nameserver - Let’s say you are purchasing a domain from google and want to use Cloudflare then you can provide Cloudflare nameserver detail in the google domain. So you are trying to say that for looking for <a target="_blank" href="http://example.com">example.com</a> detail please ask from Cloudflare nameserver.</p>
<h2 id="heading-now-lets-understand-what-happens-behind-the-scene-when-you-hit-examplecomhttpexamplecom"><strong>Now let's understand what happens behind the scene when you hit</strong> <a target="_blank" href="http://example.com"><strong>example.com</strong></a></h2>
<p>When a user types <a target="_blank" href="http://example.com">example.com</a> in a web browser, the browser checks its DNS cache to see if there is already an IP address mapping for the domain name. If there's no cache available, the browser calls the <code>gethostbyname</code> syscall to ask the operating system to find the IP address.  </p>
<p>The operating system first looks at the <code>/etc/nsswitch.conf</code> (nameserver switch) file. It contains the following information:<br /><code>hosts: files dns</code> - This means that the OS will first look up the /etc/hosts file and then use the DNS protocol if it doesn't find an entry there.<br />If the <code>/etc/hosts</code> file has an entry <code>127.0.0.1</code> <a target="_blank" href="http://example.com"><code>example.com</code></a> then browser will call the IP address 127.0.0.1. if there is no entry then, it will first request the DNS server specified in the <code>/etc/resolv.conf</code> file. (If there's no response from that server, the OS will try the next IP address.)  </p>
<p><strong><em>So how does the DNS resolver find the IP address?</em></strong><br />The DNS resolver first looks up its cache, which can be on various network devices. If there's no cache, it goes through the following steps:  </p>
<p>The DNS server breaks down "<a target="_blank" href="http://example.com">example.com</a>" into its parts.</p>
<ul>
<li><p>“.” → Root Server</p>
<p>  IP address of root server is known to DNS resolver and now it queries to root server to find the right IP of .com</p>
</li>
<li><p>“.com” → TLD NameServer (top-level domain server)</p>
<ul>
<li>DNS resolver now queries to .com server to return IP address of the authoritative nameserver of <a target="_blank" href="http://google.com">example.com</a></li>
</ul>
</li>
</ul>
<p>“<a target="_blank" href="http://google.com">example.com</a>”</p>
<ul>
<li>now DNS resolver calls the authoritative nameserver of <a target="_blank" href="http://google.com">example.com</a> to fetch the IP address of <a target="_blank" href="http://google.com">google.com</a></li>
</ul>
<p>In summary, the DNS resolver uses a hierarchical system of servers to find the IP address associated with a domain name.</p>
<p><strong><em>Shell Commands to experiments</em></strong></p>
<pre><code class="lang-bash"><span class="hljs-comment">#Run this command in one shell to capture all DNS requests</span>
&gt; sudo tcpdump -s 0 -A -i any port 53
<span class="hljs-comment"># Make a dig request from another shell</span>
&gt; dig google.com

<span class="hljs-comment"># tcpdump result</span>
17:55:51.672393 IP 192.168.1.3.60562 &gt; 192.168.1.1.domain: 64183+ [1au] A? google.com. (39)
D.;G*....,.C..E..C....@.4c...........5./W.... .........google.com.......)........
17:55:51.685685 IP 192.168.1.1.domain &gt; 192.168.1.3.60562: 64183 1/0/1 A 142.250.77.238 (55)
...,.CD.;G*...E..SgE@.@.P..........5...?9|.............google.com...................M...)........


<span class="hljs-comment"># Request made to 192.168.1.1.domain for google.com. 192.168.1.1.domain is the resolver mentioned in /etc/resolv.conf. Response received IP Address of google.com 142.250.77.238</span>

&gt; dig +trace google.com
google.com.   300      IN      A       142.250.193.46
request       ttl   class   <span class="hljs-built_in">type</span>   response

&gt; dig A facebook.com +short
157.240.239.35

&gt; dig AAAA facebook.com +short
2a03:2880:f144:181:face:b00c:0:25de

&gt; dig NS facebook.com +short
b.ns.facebook.com.
a.ns.facebook.com.
d.ns.facebook.com.
c.ns.facebook.com.

&gt; dig www.facebook.com CNAME +short
star-mini.c10r.facebook.com.
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Web Security Vulnerability & Prevention Mechanism]]></title><description><![CDATA[Type of Attacks
ClickJacking

The victim visits the attacker's website and clicks on Play but actually, the victim clicks on Pay which is from the bank.com website.
The attacker has added the iframe of the bank.com website at the top z-index and made...]]></description><link>https://blog.anuragjain.me/web-security-vulnerability-prevention-mechanism</link><guid isPermaLink="true">https://blog.anuragjain.me/web-security-vulnerability-prevention-mechanism</guid><category><![CDATA[websecurity]]></category><category><![CDATA[http-headers]]></category><category><![CDATA[HTTP security headers]]></category><dc:creator><![CDATA[Anurag Jain]]></dc:creator><pubDate>Sat, 11 Mar 2023 08:26:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/mT7lXZPjk7U/upload/dd907d6cb502265f24f392603a977f28.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-type-of-attacks">Type of Attacks</h2>
<h3 id="heading-clickjacking">ClickJacking</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1678519963481/1acd2dfd-fc06-4f8a-988e-726385c1f124.webp" alt class="image--center mx-auto" /></p>
<p>The victim visits the attacker's website and clicks on <strong>Play</strong> but actually, the victim clicks on <strong>Pay</strong> which is from the bank.com website.</p>
<p>The attacker has added the iframe of the bank.com website at the top z-index and made it transparent by setting opacity to 0. Play is just a simple component that is just below the iframe but it’s visible due to the iframe opacity being 0.</p>
<p><mark>As a user, you shouldn’t visit any malicious sites and especially shouldn’t click anywhere. Users may use a different browser for using such websites which don’t have cookies of sites.</mark></p>
<h3 id="heading-cross-site-scripting-attack">Cross-site Scripting Attack</h3>
<p>Cross-Site Scripting (XSS) is a security vulnerability that allows an attacker to inject malicious scripts or code into a website, which can then be executed by unsuspecting users who visit the site. There are multiple ways through which this can happen</p>
<p><strong>Reflected XSS</strong></p>
<p>Step1 - Attacker share URL (which contains script)</p>
<p>Step2 - Victim clicks on the url</p>
<p>Step3 - Browser Request webserver</p>
<p>Step4 - Webserver return the page with the same script</p>
<p>Step5 - The script gets executed and the script starts sharing website data with attackers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1675489793034/b405b4eb-703f-4fe6-b2a5-473779b10b74.png" alt /></p>
<p><strong>Stored XSS</strong></p>
<p>Step1 - The attacker uploads script on the Website</p>
<p>Step2 - Website store the script</p>
<p>Step3 - Victim opens the website</p>
<p>Step4 - Webserver returns a page with the same script</p>
<p>Step5 - The browser executes the script and starts sharing user data with the Attacker.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1675489797705/d9bb2380-cc22-41dc-ba40-0dec47901c13.png" alt /></p>
<h3 id="heading-mime-sniffing-attack">Mime Sniffing Attack</h3>
<p>MIME sniffing is a security vulnerability that can occur when a web browser attempts to determine the correct MIME type (file type) of a resource based on its content, rather than relying on the server-provided Content-Type header.</p>
<p>For example, an attacker could upload a malicious script to a website with a fake file extension that looks harmless (such as a .jpg or .gif file) but contains JavaScript code. If the server does not properly set the Content-Type header, the browser may attempt to "sniff" the file type and execute the script, allowing the attacker to execute arbitrary code or steal sensitive information.</p>
<h3 id="heading-cross-site-websocket-hijacking">Cross-Site WebSocket Hijacking</h3>
<p>Cross-Site WebSocket Hijacking (CSWSH) is a type of attack that exploits WebSocket connections to allow an attacker to execute arbitrary code or steal sensitive information from a victim's browser.</p>
<h2 id="heading-security-practices-can-prevent-these-attacks">Security Practices can prevent these attacks</h2>
<h3 id="heading-add-http-response-header-x-frame-options">Add HTTP Response Header - X-Frame-Options</h3>
<p>Web developers can use the X-Frame-Options header to instruct the browser not to display their website in an iframe. The header can be set to one of three values: "DENY", "SAMEORIGIN", or "ALLOW-FROM uri".</p>
<p><code>X-Frame-Options: SAMEORIGIN</code></p>
<p>This prevents ClickJacking attacks.</p>
<h3 id="heading-add-http-response-header-content-security-policy">Add HTTP Response Header - Content-Security-Policy</h3>
<p>Content Security Policy (CSP) can use to control which resources (such as images, scripts, stylesheets, and fonts) are allowed to be loaded by their web application on the browser.</p>
<p><code>Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'</code> <a target="_blank" href="https://example.com"><code>https://example.com</code></a><code>;</code></p>
<p>This prevents Cross Site Scripting attacks.</p>
<h3 id="heading-add-http-response-header-x-content-type-option">Add HTTP Response Header - X-Content-Type-Option</h3>
<p>The X-Content-Type-Options header guide browser on whether it should determine the mime type automatically or not.</p>
<p>By setting the header to "nosniff" developers can ensure that the browser always uses the specified MIME type, and prevent attackers from exploiting vulnerabilities that rely on MIME sniffing.</p>
<p><code>X-Content-Type-Options: nosniff</code></p>
<p>This prevents Mime Sniffing attacks.</p>
<h3 id="heading-add-http-response-header-referer-policy">Add HTTP Response Header - Referer Policy</h3>
<p>The browser sends referer information to a new page/site when the user navigates to a new page. This feature can lead to security issues For example if a website has a lax Referer Policy that allows the Referer header to be sent to all third-party sites, an attacker could potentially use this information to track users across multiple sites or to collect sensitive information about the user's browsing habits.</p>
<p>By setting an appropriate Referer Policy, website owners can reduce the risk for users:</p>
<ol>
<li><p><code>no-referrer</code>: This value tells the browser not to send the <code>Referer</code> header at all when navigating to another website. This means that the target website will not know which page the user came from.</p>
</li>
<li><p><code>no-referrer-when-downgrade</code>: This value tells the browser to send the <code>Referer</code> header when navigating to a website that uses HTTPS, but not when navigating to a website that uses HTTP.</p>
</li>
<li><p><code>same-origin</code>: This value tells the browser to send the <code>Referer</code> header only when navigating to another page on the same origin (i.e., same scheme, hostname, and port).</p>
</li>
<li><p><code>strict-origin</code>: This value tells the browser to send the <code>Referer</code> header when navigating to a page on the same origin, but not when navigating to a different origin.</p>
</li>
<li><p><code>origin</code>: This value tells the browser to send the <code>Referer</code> header with just the scheme, hostname, and port of the referring page, but not the path or query string.</p>
</li>
<li><p><code>strict-origin-when-cross-origin</code>: This value is similar to <code>strict-origin</code>, but it allows the <code>Referer</code> header to be sent when navigating from one origin to another if and only if the HTTP method is safe (i.e., GET, HEAD, or OPTIONS).</p>
</li>
</ol>
<h3 id="heading-always-do-websocket-origin-validation">Always do WebSocket Origin Validation</h3>
<p>Cross-Origin Validation is not being done by the browser when it's WebSocket connection. And hence Validating the origin of WebSocket connections is an important security measure to prevent unauthorized access and protect against Cross-Site WebSocket Hijacking (CSWSH) attacks.</p>
<p>If the server does not validate the <code>Origin</code> header, an attacker could potentially use a malicious webpage to establish a WebSocket connection to the server and execute arbitrary code or steal sensitive information.</p>
<h3 id="heading-reference">Reference</h3>
<iframe src="https://www.youtube.com/embed/PPzn4K2ZjfY?feature=oembed" width="700" height="393"></iframe>

<iframe src="https://www.youtube.com/embed/cWu_FJUrH5Y?feature=oembed" width="700" height="393"></iframe>

<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=8_nfQAdWELU&amp;ab_channel=BittenTech">https://www.youtube.com/watch?v=8_nfQAdWELU&amp;ab_channel=BittenTech</a></div>
]]></content:encoded></item><item><title><![CDATA[Understanding API Gateway, Backend For Frontend]]></title><description><![CDATA[Understanding API gateway
If you're working on a microservices architecture with multiple services and would like to expose your APIs to external developers, several requirements need to be considered.
These requirements include

Authentication: Auth...]]></description><link>https://blog.anuragjain.me/understanding-api-gateway-backend-for-frontend</link><guid isPermaLink="true">https://blog.anuragjain.me/understanding-api-gateway-backend-for-frontend</guid><category><![CDATA[API Gateway]]></category><category><![CDATA[Backend for frontend]]></category><category><![CDATA[apigee]]></category><category><![CDATA[bff]]></category><dc:creator><![CDATA[Anurag Jain]]></dc:creator><pubDate>Sun, 26 Feb 2023 19:06:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/SRcCvI79WRw/upload/862fc8622367b8bdac599a629d2765b9.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-understanding-api-gateway">Understanding API gateway</h2>
<p>If you're working on a microservices architecture with multiple services and would like to expose your APIs to external developers, several requirements need to be considered.</p>
<p>These requirements include</p>
<ol>
<li><p><strong><em>Authentication:</em></strong> Authentication is the process of verifying the identity of the user or system trying to access the APIs. An API gateway can apply authentication mechanisms such as OAuth2, JWT, or API keys to ensure that only authorized users or systems can access the APIs.</p>
</li>
<li><p><strong><em>Rate Limitation:</em></strong> Rate limitation is the process of limiting the number of requests that a user or system can make to the APIs within a certain time period. An API gateway can enforce rate limits on a per-user or per-service basis to prevent overload on the underlying microservices.</p>
</li>
<li><p><strong><em>Transformations</em></strong> on the request/response layer: Transformations on the request/response layer involve modifying or transforming the incoming requests and outgoing responses to the APIs. An API gateway can apply transformations such as message routing, filtering, content-based routing, or payload modification to ensure that the requests and responses are in the expected format and are compatible with the underlying microservices.</p>
</li>
<li><p><strong><em>Different quotas</em></strong> based on developer types: Different quotas based on developer types involve setting different limits on the number of requests or resources that a user or system can access based on their membership level. An API gateway can provide different quotas for standard developers and premium developers, for example, by limiting the number of requests, the amount of data retrieved, or the frequency of API calls.</p>
</li>
<li><p><strong><em>Different APIs</em></strong> are exposed based on developer types: Different APIs exposed based on developer types involve providing different sets of APIs to different users or systems based on their membership level. An API gateway can expose different APIs for standard developers and premium developers, for example, by hiding some APIs from standard developers and exposing more APIs to premium developers. This can be useful in monetizing the APIs and providing different levels of service to different customers.</p>
</li>
<li><p><strong>Customize API</strong> that can mix all microservices complex logics and return output to make the external developer's life easier. In a microservices architecture, there may be several services that an external developer needs to access in order to complete a task. For example, a developer may need to interact with one service to retrieve user data, another service to retrieve product information, and yet another service to complete a transaction. To simplify this process, an API gateway can be configured to expose a separate API that combines all microservices and returns output to external developers. This separate API acts as a facade, hiding the complexities of the microservices architecture from external developers and providing a simpler interface for them to use. The API gateway takes care of routing requests to the appropriate microservices and aggregating their responses into a single output. This means that external developers can interact with a single endpoint and receive the necessary information from all the connected microservices.</p>
</li>
</ol>
<p>To fulfill these requirements, an API gateway can be used to securely expose your APIs to external developers. By using an API gateway, internal services do not need to write these logics at their end. Instead, the API gateway will take care of all the requirements, such as managing authentication and rate limitations, applying transformations on the request/response layer, and providing different quotas and APIs based on the developer's type.</p>
<p>API Gateway can also perform additional functions, such as caching, logging, and monitoring. In addition, API Gateway provides API lifecycle management, which includes tasks such as creating, testing, deploying, versioning, and retiring APIs. By managing the API lifecycle in a centralized way, API Gateway can help ensure that APIs are developed, deployed, and retired consistently and in a controlled manner, reducing the risk of errors or security issues.</p>
<h2 id="heading-understanding-bff">Understanding BFF</h2>
<p>BFF, or Backend For Frontend, is an API gateway that is designed to serve front-end clients only. In a microservices architecture, there may be several internal services that a front-end or mobile application needs to access in order to create views that combine information from multiple services.</p>
<p>By introducing a BFF layer, you can take advantage of several benefits:</p>
<ol>
<li><p>You can write all your front-end related logic in the BFF layer. This means that the internal microservices can remain focused on their core functionality, while the BFF handles any front-end-specific logic.</p>
</li>
<li><p>The BFF layer can act as a facade for the internal microservices, exposing a unified API that is tailored to the needs of the front-end application. This can simplify the front-end code and reduce the number of network requests needed to create a view.</p>
</li>
<li><p>You don't need to expose your internal services to the public. By routing all requests through the BFF layer, you can keep your internal services behind a firewall and only expose the BFF to the outside world.</p>
</li>
<li><p>Writing a BFF layer can help you manage authentication at the BFF level. While authorization may still need to be handled at the service level, the BFF layer can handle authentication for all requests, making it easier to manage security.</p>
</li>
<li><p>The BFF layer can also act as a filtering layer, allowing you to restrict which data is exposed to the front-end application. This can be particularly useful if your internal services expose data that should not be returned to front-end clients. By routing requests through the BFF, you can control which data is returned to the client, while still allowing internal services to function as intended.</p>
</li>
</ol>
<p>One question that often comes up is whether introducing a BFF layer will create <strong><em>latency</em></strong>. While it is true that the BFF layer adds an extra hop in the request/response chain, the network latency can be reduced by batching multiple requests together and reducing the number of network calls that need to be made by the front-end application. Additionally, the BFF layer can cache responses and handle load balancing, further reducing latency and improving overall performance.</p>
<h2 id="heading-api-gateway-vs-bff">API-gateway vs BFF</h2>
<p>API Gateway acts as a middleman between your internal microservices and external clients. Its main job is to provide a single interface for external clients to access your microservices while taking care of tasks like authentication, rate limiting, and routing requests to the right microservice. Additionally, API Gateway can perform other tasks like caching, logging, and monitoring.</p>
<p>BFF, on the other hand, sits between your internal microservices and your front-end clients, like mobile or web applications. Its main purpose is to simplify the front-end code by acting as a façade for your microservices and providing a tailored API that meets the needs of your front-end application.</p>
<p>In summary, while API Gateway is designed to handle external clients and provide a unified API to multiple types of clients, BFF is designed to handle front-end clients only and simplify the front-end code. Both API Gateway and BFF can help you manage and expose your microservices securely and efficiently, but they serve different purposes and are tailored to different types of clients.</p>
<h2 id="heading-references">References</h2>
<p><a target="_blank" href="https://samnewman.io/patterns/architectural/bff/#comment-2923121019">https://samnewman.io/patterns/architectural/bff/#comment-2923121019</a></p>
<p><a target="_blank" href="https://kuroco.app/blog/api-management/2022/05/05/api-gateway-vs-backend-for-frontend/">https://kuroco.app/blog/api-management/2022/05/05/api-gateway-vs-backend-for-frontend/</a></p>
<p><a target="_blank" href="https://www.googlecloudcommunity.com/gc/Apigee/Can-we-get-rid-of-Backend-For-Frontend-when-using-an-API-Gateway/m-p/423745">https://www.googlecloudcommunity.com/gc/Apigee/Can-we-get-rid-of-Backend-For-Frontend-when-using-an-API-Gateway/m-p/423745</a></p>
<p><a target="_blank" href="https://medium.com/@abhilashjn85/bff-layer-when-its-more-than-just-an-api-gateway-4679da49534c">https://medium.com/@abhilashjn85/bff-layer-when-its-more-than-just-an-api-gateway-4679da49534c</a></p>
]]></content:encoded></item></channel></rss>