<?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>DEV Community: Harshit Sharma</title>
    <description>The latest articles on DEV Community by Harshit Sharma (@harshit_sharma_83a1c3b54e).</description>
    <link>https://dev.to/harshit_sharma_83a1c3b54e</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%2F3521928%2F029877f7-62fe-4dd8-81cd-03d40434f228.png</url>
      <title>DEV Community: Harshit Sharma</title>
      <link>https://dev.to/harshit_sharma_83a1c3b54e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harshit_sharma_83a1c3b54e"/>
    <language>en</language>
    <item>
      <title>API Gateway vs Varnish for API Security &amp; Traffic Control</title>
      <dc:creator>Harshit Sharma</dc:creator>
      <pubDate>Mon, 22 Sep 2025 12:27:28 +0000</pubDate>
      <link>https://dev.to/harshit_sharma_83a1c3b54e/api-gateway-vs-varnish-for-api-security-traffic-control-n24</link>
      <guid>https://dev.to/harshit_sharma_83a1c3b54e/api-gateway-vs-varnish-for-api-security-traffic-control-n24</guid>
      <description>&lt;p&gt;We operate a backend API stack on GCP. Currently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Varnish handles caching + SourceIP authentication.&lt;br&gt;
(IP refers to the infrastructure servers’ IPs, while Source is a URL parameter passed in API calls that identifies the property.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Both Varnish and backend run on the same GCP server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we scale for resilience and performance, we need to implement:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication &amp;amp; Validation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Route requests to the correct backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enforce API key + SourceIP-based auth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate identities via parameters:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Source (URL param, used in backend calls)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IP (frontend server IPs)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;USR-ID (end-user ID, from URL param)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rate Limiting&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Based on Source + IP + USR-ID.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alert at x% of the threshold. Block at y% (API Gateway) or z% (Varnish).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configurable block durations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Circuit Breaking / Backend Protection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Stop routing on backend failure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note: In Varnish, we use a heartbeat health-check mechanism that is similar to a circuit breaker, but not a true implementation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Logging &amp;amp; Observability&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Track rate-limit breaches, blocks, circuit-breaking events, and request metadata.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Alerts on abnormal traffic or backend failures.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Options We’re Considering&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;API Gateway (New Development)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Central entry point for traffic.&lt;/li&gt;
&lt;li&gt;Handles auth, routing, rate limiting, logging, and observability.&lt;/li&gt;
&lt;li&gt;Centralised logic → easier management as APIs grow.&lt;/li&gt;
&lt;li&gt;Adds an extra hop, but increases visibility + maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Enhanced Varnish (Current, with Modifications)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Already deployed per server.&lt;/li&gt;
&lt;li&gt;Would need manual updates for: rate limiting (Source/IP/USR-ID), logging, and backend protection.&lt;/li&gt;
&lt;li&gt;No true circuit breaker, but can serve stale cache or block during backend downtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Questions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Centralisation vs Distribution: Better to centralise controls in an API Gateway, or enhance Varnish on each server??&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performance &amp;amp; Maintenance: Does the extra hop of an API Gateway outweigh its benefits in observability and control??&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scaling with Varnish: How do you avoid config drift and manage scaling in a Varnish-based setup??&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deployment Topology: Should Varnish and backend run on the same GCP server, or be separated for resilience??&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-World Experiences: Has anyone migrated from Varnish-based controls to an API Gateway?? What worked, what didn’t??&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-world experiences&lt;/li&gt;
&lt;li&gt;Best practices&lt;/li&gt;
&lt;li&gt;Resource recommendations&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>apigateway</category>
      <category>varnish</category>
      <category>backend</category>
      <category>backenddevelopment</category>
    </item>
  </channel>
</rss>
