<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Backend Weekly</title>
    <description>Explain complex concepts in Backend Engineering, sharing exclusive backend engineering resources, and helping you become a great Backend Engineer.</description>
    
    <link>https://newsletter.masteringbackend.com/</link>
    <atom:link href="https://rss.beehiiv.com/feeds/PCxR7slc9e.xml" rel="self"/>
    
    <lastBuildDate>Thu, 14 May 2026 23:27:26 +0000</lastBuildDate>
    <pubDate>Fri, 27 Jun 2025 07:20:30 +0000</pubDate>
    <atom:published>2025-06-27T07:20:30Z</atom:published>
    <atom:updated>2026-05-14T23:27:26Z</atom:updated>
    
      <category>Programming</category>
      <category>Technology</category>
    <copyright>Copyright 2026, Backend Weekly</copyright>
    
    <image>
      <url>https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/publication/logo/f89b2662-103e-4d1a-b7d0-be7faf688586/BackendWeekly_logo.png</url>
      <title>Backend Weekly</title>
      <link>https://newsletter.masteringbackend.com/</link>
    </image>
    
    <docs>https://www.rssboard.org/rss-specification</docs>
    <generator>beehiiv</generator>
    <language>en-us</language>
    <webMaster>support@beehiiv.com (Beehiiv Support)</webMaster>

      <item>
  <title>API and API Design: API Security (part 2)</title>
  <description>In this issue, we will continue with API Security and cover the remaining 6 API security tips from the OWASP 10</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-api-security-part-2</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-api-security-part-2</guid>
  <pubDate>Fri, 27 Jun 2025 07:20:30 +0000</pubDate>
  <atom:published>2025-06-27T07:20:30Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
    <category><![CDATA[Restful Api]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. Learn backend development practically.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Still stuck in tutorial hell?</p><p class="paragraph" style="text-align:left;">We’ve all been there—jumping from one Python video to the next, but never building anything real.<br>No portfolio. No confidence. No callbacks.</p><p class="paragraph" style="text-align:left;">That’s why I created this.</p><p class="paragraph" style="text-align:left;"><b>The “Land Your Dream Python Job” Challenge</b><br>A 90-day, 3-phase roadmap that helps you:</p><p class="paragraph" style="text-align:left;">✅ Build 30 real-world backend projects in 30 days<br>✅ Master DSA for technical interviews<br>✅ Get job-ready with resumes, mock interviews & daily job alerts<br>✅ And finally... land that backend job</p><p class="paragraph" style="text-align:left;">This is NOT another course. It’s a challenge. And it <i>works</i>.</p><p class="paragraph" style="text-align:left;">Over <b>2,000 Python developers</b> have taken this path—many are now working at top companies.</p><p class="paragraph" style="text-align:left;"><b>Only 120 slots left at $54 (then goes up to $100)</b></p><p class="paragraph" style="text-align:left;">Join the challenge & change your future<br>👉 <a class="link" href="https://python30.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">python30.masteringbackend.com</a></p><p class="paragraph" style="text-align:left;">Let’s get you unstuck.</p><hr class="content_break"><h3 class="heading" style="text-align:left;" id="looking-for-unbiased-factbased-news">Looking for unbiased, fact-based news? Join 1440 today.</h3><div class="image"><a class="image__link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_14809c76-b268-4f31-ac45-6a1cbe6c1940_1b75ca79&bhcl_id=e1bf0ca8-c515-4531-9fa3-0a06b234381e_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/1bcbfe03-863a-4193-a587-c366a30d8a46/TopicBrain-TrustedByOver4Million.jpg?t=1743467156"/></a></div><p class="paragraph" style="text-align:left;">Join over 4 million Americans who start their day with <a class="link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_14809c76-b268-4f31-ac45-6a1cbe6c1940_1b75ca79&bhcl_id=e1bf0ca8-c515-4531-9fa3-0a06b234381e_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">1440</a> – your daily digest for unbiased, fact-centric news. From politics to sports, we cover it all by analyzing over 100 sources. Our concise, 5-minute read lands in your inbox each morning at no cost. Experience news without the noise; let 1440 help you make up your own mind. Sign up now and invite your friends and family to be part of the informed.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_14809c76-b268-4f31-ac45-6a1cbe6c1940_1b75ca79&bhcl_id=e1bf0ca8-c515-4531-9fa3-0a06b234381e_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Subscribe to 1440 today.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Welcome to another episode of Backend Weekly, previously, I covered the <a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-api-security?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">top 4 security risks from OWASP Top 10</a>, and in this issue, I will continue with API Security and cover the remaining 6 API security tips from the OWASP 10 list below:</p><p class="paragraph" style="text-align:left;">✅ Broken Authentication<br>✅ Broken Object Level Authorization<br>✅ Broken Object Property Level Authorization<br>✅ Unrestricted Resource Consumption<br><br>Next, I will cover the following:</p><ul><li><p class="paragraph" style="text-align:left;">Broken Function Level Authorization</p></li><li><p class="paragraph" style="text-align:left;">Unrestricted Access to Sensitive Business Flows</p></li><li><p class="paragraph" style="text-align:left;">Server-Side Request Forgery</p></li><li><p class="paragraph" style="text-align:left;">Security Misconfiguration</p></li><li><p class="paragraph" style="text-align:left;">Improper Inventory Management</p></li><li><p class="paragraph" style="text-align:left;">Unsafe Consumption of APIs</p></li></ul><h2 class="heading" style="text-align:left;" id="broken-function-level-authorization">Broken Function Level Authorization</h2><p class="paragraph" style="text-align:left;">This issue is listed in the OWASP API Security Top 10 as API5 – Broken Function Level Authorization. </p><p class="paragraph" style="text-align:left;">It occurs when APIs expose endpoints that don’t properly check whether the authenticated user has permission to access the function being called. </p><p class="paragraph" style="text-align:left;">Complex access control policies—such as those involving user roles, groups, and permissions—can lead to improper checks or lack of authorization logic altogether.</p><h3 class="heading" style="text-align:left;" id="example">Example:</h3><p class="paragraph" style="text-align:left;">Below is an example that covers the broken function level authorization security bridge and some of the possible solutions. Suppose an API has both regular users and admin users, but it fails to enforce role-based authorization:</p><div class="codeblock"><pre><code>// INSECURE: No role check — anyone can access admin route
app.delete(&#39;/admin/delete-user/:id&#39;, async (req, res) =&gt; &#123;
  await db.User.deleteOne(&#123; _id: req.params.id &#125;);
  res.send(&#39;User deleted&#39;);
&#125;);</code></pre></div><h3 class="heading" style="text-align:left;" id="solution">Solution:</h3><p class="paragraph" style="text-align:left;">Implement middleware to enforce role-based access control (RBAC):</p><div class="codeblock"><pre><code>function requireAdmin(req, res, next) &#123;
  if (req.user.role !== &#39;admin&#39;) &#123;
    return res.status(403).send(&#39;Access denied&#39;);
  &#125;
  next();
&#125;

app.delete(&#39;/admin/delete-user/:id&#39;, requireAdmin, async (req, res) =&gt; &#123;
  await db.User.deleteOne(&#123; _id: req.params.id &#125;);
  res.send(&#39;User deleted&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">Additionally, ensure that roles are properly validated during login and token creation:</p><div class="codeblock"><pre><code>const token = jwt.sign(&#123; id: user.id, role: user.role &#125;, process.env.JWT_SECRET);</code></pre></div><p class="paragraph" style="text-align:left;">By adding a clear separation of duties and verifying access based on user role or group, APIs can better prevent unauthorized access to sensitive operations.</p><h2 class="heading" style="text-align:left;" id="unrestricted-access-to-sensitive-bu">Unrestricted Access to Sensitive Business Flows</h2><p class="paragraph" style="text-align:left;">This vulnerability is defined in the OWASP API Security Top 10 (2023) as API6 – Unrestricted Access to Sensitive Business Flows. It arises not from code bugs, but from a lack of strategic business rule enforcement.</p><p class="paragraph" style="text-align:left;">APIs may expose critical operations—like purchasing items, creating accounts, or submitting comments—without considering how these operations could be abused at scale. This allows attackers or bots to overwhelm business services in ways that hurt revenue, credibility, or functionality.</p><h3 class="heading" style="text-align:left;" id="example">Example:</h3><p class="paragraph" style="text-align:left;">Suppose you have an endpoint that allows users to post comments on a product:</p><div class="codeblock"><pre><code>// INSECURE: No user limits, abuse protection, or flow control
app.post(&#39;/products/:id/comment&#39;, async (req, res) =&gt; &#123;
  const &#123; comment &#125; = req.body;
  const &#123; id &#125; = req.params;
  await db.Comment.create(&#123; productId: id, userId: req.user.id, text: comment &#125;);
  res.send(&#39;Comment added&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">A spam bot could hit this endpoint thousands of times, flooding your app with spam and damaging trust with legitimate users.</p><h3 class="heading" style="text-align:left;" id="solution">Solution:</h3><p class="paragraph" style="text-align:left;">Introduce safeguards including:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Rate limiting</b> to restrict frequency.</p></li><li><p class="paragraph" style="text-align:left;"><b>Behavioral analysis</b> to detect bots.</p></li><li><p class="paragraph" style="text-align:left;"><b>Business logic</b> rules to cap use (e.g., one comment per user per 10 minutes).</p></li></ul><div class="codeblock"><pre><code>const rateLimit = require(&#39;express-rate-limit&#39;);

const commentLimiter = rateLimit(&#123;
  windowMs: 10 * 60 * 1000, // 10 minutes
  max: 3, // Max 3 comments per window
  message: &#39;Commenting too frequently. Please slow down.&#39;
&#125;);

app.post(&#39;/products/:id/comment&#39;, commentLimiter, async (req, res) =&gt; &#123;
  const &#123; comment &#125; = req.body;
  const &#123; id &#125; = req.params;

  const recent = await db.Comment.find(&#123;
    productId: id,
    userId: req.user.id,
    createdAt: &#123; $gte: new Date(Date.now() - 10 * 60 * 1000) &#125;
  &#125;);

  if (recent.length &gt;= 1) &#123;
    return res.status(429).send(&#39;You can only comment once every 10 minutes.&#39;);
  &#125;

  await db.Comment.create(&#123; productId: id, userId: req.user.id, text: comment &#125;);
  res.send(&#39;Comment added&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">This ensures sensitive flows are governed by rate and relevance, reducing the risk of economic abuse or reputational harm.</p><h2 class="heading" style="text-align:left;" id="server-side-request-forgery">Server-Side Request Forgery</h2><p class="paragraph" style="text-align:left;">This vulnerability is listed under OWASP API Security Top 10: API7 – Server Side Request Forgery. </p><p class="paragraph" style="text-align:left;">SSRF vulnerabilities occur when an API endpoint allows users to specify URLs or IP addresses to fetch remote resources, but the server does not adequately validate these inputs. </p><p class="paragraph" style="text-align:left;">Attackers exploit this to make the server issue requests to internal systems, cloud metadata endpoints, or other protected environments.</p><h2 class="heading" style="text-align:left;" id="example">Example:</h2><p class="paragraph" style="text-align:left;">Here&#39;s an example of a vulnerable Node.js/Express endpoint that accepts a URL as input:</p><div class="codeblock"><pre><code>// INSECURE: No input validation, direct use of user-supplied URL
const axios = require(&#39;axios&#39;);

app.get(&#39;/proxy&#39;, async (req, res) =&gt; &#123;
  const &#123; url &#125; = req.query;
  try &#123;
    const response = await axios.get(url);
    res.send(response.data);
  &#125; catch (err) &#123;
    res.status(500).send(&#39;Error fetching resource&#39;);
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">With this implementation, a malicious actor can make the server request internal URLs such as:</p><div class="codeblock"><pre><code>GET /proxy?url=http://localhost:8000/admin
GET /proxy?url=http://169.254.169.254/latest/meta-data/  // AWS metadata</code></pre></div><p class="paragraph" style="text-align:left;">This can lead to data exfiltration or allow attackers to bypass firewall protections.</p><h3 class="heading" style="text-align:left;" id="solution">Solution:</h3><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Implement input validation</b> to allow only approved domains.</p></li><li><p class="paragraph" style="text-align:left;"><b>Use allowlists</b> to define safe URLs or domains.</p></li><li><p class="paragraph" style="text-align:left;"><b>Disallow local IPs</b> like <code>127.0.0.1</code>, <code>169.254.x.x</code>, and internal ranges.</p></li></ol><div class="codeblock"><pre><code>const dns = require(&#39;dns&#39;);
const isValidUrl = require(&#39;valid-url&#39;);

app.get(&#39;/proxy&#39;, async (req, res) =&gt; &#123;
  const &#123; url &#125; = req.query;

  if (!isValidUrl.isUri(url)) &#123;
    return res.status(400).send(&#39;Invalid URL&#39;);
  &#125;

  const parsedUrl = new URL(url);
  const hostname = parsedUrl.hostname;

  // Only allow requests to a predefined list of domains
  const allowedHosts = [&#39;example.com&#39;, &#39;api.trusted.com&#39;];
  if (!allowedHosts.includes(hostname)) &#123;
    return res.status(403).send(&#39;Access denied&#39;);
  &#125;

  try &#123;
    const response = await axios.get(url);
    res.send(response.data);
  &#125; catch (err) &#123;
    res.status(500).send(&#39;Error fetching resource&#39;);
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">In highly sensitive applications, use an external proxy layer to isolate request fetching from your API server entirely.</p><p class="paragraph" style="text-align:left;">APIs are essential to the architecture of modern software systems, but they also introduce new security risks. API security must be integrated from the earliest stages of design and remain a continuous practice throughout development and operation.</p><p class="paragraph" style="text-align:left;">As APIs grow in number and complexity, so do the threats. Prioritize security, implement best practices, and choose the right tools to safeguard your API ecosystem.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security-part-2" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=8ab23c12-214c-4e1a-ad2f-687869f13f1c&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: API Security</title>
  <description>APIs are essential to the architecture of modern software systems, but they also introduce new security risks. In this issue, we explored API Security and the OWASP Top 10.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-api-security</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-api-security</guid>
  <pubDate>Mon, 16 Jun 2025 12:01:10 +0000</pubDate>
  <atom:published>2025-06-16T12:01:10Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. Learn backend development practically.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to landing your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 120 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-join-the-challenge"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Click here to join the challenge.</a></b></h1><hr class="content_break"><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">Securing an API is not an afterthought—it is a fundamental aspect of the API design lifecycle.</p><p class="paragraph" style="text-align:left;">As APIs increasingly serve as the connective tissue of modern applications, their exposure to the internet makes them attractive targets for cyberattacks.</p><p class="paragraph" style="text-align:left;">Proper API security ensures that an API reliably fulfills its intended purpose while safeguarding sensitive data, maintaining service availability, and upholding user trust.</p><p class="paragraph" style="text-align:left;"><b>API security</b> is a set of strategies, practices, and technologies designed to protect APIs from unauthorized access, abuse, data breaches, and performance degradation.</p><h2 class="heading" style="text-align:left;" id="what-is-api-security">What is API Security?</h2><p class="paragraph" style="text-align:left;"><b>API security</b> encompasses the practices and tools used to secure APIs throughout their entire lifecycle. This includes measures to authenticate users, authorize access, validate inputs, encrypt data, limit usage, monitor behavior, and handle threats.</p><p class="paragraph" style="text-align:left;">APIs expose business logic and data to a variety of clients—including browsers, mobile apps, third-party services, and IoT devices. Because of this broad exposure, any weakness in API design can become an attack vector.</p><p class="paragraph" style="text-align:left;">Below are some of the core objectives of API Security:</p><h3 class="heading" style="text-align:left;" id="core-objectives-of-api-security">Core Objectives of API Security</h3><ul><li><p class="paragraph" style="text-align:left;">Prevent <b>unauthorized access</b> to sensitive resources.</p></li><li><p class="paragraph" style="text-align:left;">Protect against <b>data leaks</b> and <b>injection attacks</b>.</p></li><li><p class="paragraph" style="text-align:left;">Ensure <b>high availability</b> and mitigate DoS attacks.</p></li><li><p class="paragraph" style="text-align:left;">Preserve <b>data integrity</b> and <b>privacy</b>.</p></li></ul><p class="paragraph" style="text-align:left;">Next, let’s explore some of the common API Security Threats according to OWASP Top 10 API Security report.</p><h2 class="heading" style="text-align:left;" id="common-api-security-threats">Common API Security Threats</h2><p class="paragraph" style="text-align:left;">According to <a class="link" href="https://owasp.org/API-Security/editions/2023/en/0x00-toc/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">OWASP Top 10 API Security 2023</a>, there are top 10 web and API security vulnerabilities that should be implemented on every API by API developers, and below is the list of them.</p><ul><li><p class="paragraph" style="text-align:left;">Broken Authentication</p></li><li><p class="paragraph" style="text-align:left;">Broken Object Level Authorization</p></li><li><p class="paragraph" style="text-align:left;">Broken Object Property Level Authorization</p></li><li><p class="paragraph" style="text-align:left;">Unrestricted Resource Consumption</p></li><li><p class="paragraph" style="text-align:left;">Broken Function Level Authorization</p></li><li><p class="paragraph" style="text-align:left;">Unrestricted Access to Sensitive Business Flows</p></li><li><p class="paragraph" style="text-align:left;">Server-Side Request Forgery</p></li><li><p class="paragraph" style="text-align:left;">Security Misconfiguration</p></li><li><p class="paragraph" style="text-align:left;">Improper Inventory Management</p></li><li><p class="paragraph" style="text-align:left;">Unsafe Consumption of APIs</p></li></ul><h2 class="heading" style="text-align:left;" id="broken-authentication"><b>Broken Authentication</b></h2><p class="paragraph" style="text-align:left;">APIs that fail to correctly validate tokens or credentials may allow unauthorized access. For example, consider a Node.js API using JWT for authentication but failing to verify the token properly:</p><div class="codeblock"><pre><code>// INSECURE: Token is extracted but not verified
app.get(&#39;/secure-data&#39;, (req, res) =&gt; &#123;
  const token = req.headers[&#39;authorization&#39;];
  const decoded = jwt.decode(token); // decode() does not verify signature
  if (!decoded) return res.status(401).send(&#39;Unauthorized&#39;);
  res.send(&#39;Sensitive data&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">In this scenario, any user could tamper with or forge a token and gain access to protected routes because the server does not verify the signature of the JWT.</p><h3 class="heading" style="text-align:left;" id="solution">Solution:</h3><p class="paragraph" style="text-align:left;">Use <code>jwt.verify()</code> to ensure the token&#39;s integrity and authenticity:</p><div class="codeblock"><pre><code>const jwt = require(&#39;jsonwebtoken&#39;);

app.get(&#39;/secure-data&#39;, (req, res) =&gt; &#123;
  const token = req.headers[&#39;authorization&#39;]?.split(&#39; &#39;)[1];
  if (!token) return res.status(401).send(&#39;Token missing&#39;);

  try &#123;
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    req.user = decoded;
    res.send(&#39;Sensitive data&#39;);
  &#125; catch (err) &#123;
    res.status(403).send(&#39;Invalid token&#39;);
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">This ensures that the token was not tampered with and that only authenticated users can access protected endpoints.</p><h2 class="heading" style="text-align:left;" id="excessive-data-exposure">Excessive Data Exposure</h2><p class="paragraph" style="text-align:left;">Sending too much data in API responses can reveal sensitive or internal information, especially if the backend inadvertently sends entire database records or fields that should be hidden. This issue is covered under OWASP API Security Top 10: API3 – Excessive Data Exposure.</p><p class="paragraph" style="text-align:left;">Consider this insecure Node.js/Express example:</p><div class="codeblock"><pre><code>// INSECURE: returns all user fields including sensitive data
app.get(&#39;/user/:id&#39;, async (req, res) =&gt; &#123;
  const user = await db.User.findById(req.params.id);
  res.json(user); // Sends password hash, tokens, internal flags, etc.
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">In this code, sensitive information such as password hashes, tokens, or internal flags might be leaked in the API response.</p><h4 class="heading" style="text-align:left;" id="solution">Solution:</h4><p class="paragraph" style="text-align:left;">Use selective field projection or response filtering to return only what’s needed:</p><div class="codeblock"><pre><code>// SECURE: Sends only public-facing user fields
app.get(&#39;/user/:id&#39;, async (req, res) =&gt; &#123;
  const user = await db.User.findById(req.params.id);
  if (!user) return res.status(404).send(&#39;User not found&#39;);

  const safeResponse = &#123;
    id: user.id,
    name: user.name,
    email: user.email
  &#125;;

  res.json(safeResponse);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">Alternatively, many ORMs like Mongoose offer built-in projection:</p><div class="codeblock"><pre><code>const user = await User.findById(req.params.id).select(&#39;id name email&#39;);</code></pre></div><p class="paragraph" style="text-align:left;">By explicitly defining the fields returned in API responses, developers can avoid leaking sensitive internal data and ensure better adherence to the principle of least privilege.</p><h2 class="heading" style="text-align:left;" id="lack-of-rate-limiting">Lack of Rate Limiting</h2><p class="paragraph" style="text-align:left;">Without usage limits, APIs are vulnerable to brute-force attacks and abuse. Attackers can exploit endpoints by sending repeated requests to guess credentials, flood the system with traffic, or scrape data uncontrollably.</p><p class="paragraph" style="text-align:left;">Here’s a Node.js/Express example that lacks rate limiting:</p><div class="codeblock"><pre><code>// INSECURE: No rate limiting middleware
app.post(&#39;/login&#39;, async (req, res) =&gt; &#123;
  const &#123; username, password &#125; = req.body;
  const user = await db.User.findOne(&#123; username &#125;);
  if (!user || user.password !== password) return res.status(401).send(&#39;Invalid credentials&#39;);
  res.send(&#39;Logged in&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">In this case, a malicious actor could automate requests to brute-force user credentials, overwhelming the system or gaining unauthorized access.</p><h4 class="heading" style="text-align:left;" id="solution">Solution:</h4><p class="paragraph" style="text-align:left;">Implement rate-limiting middleware using <code>express-rate-limit</code> </p><div class="codeblock"><pre><code>const rateLimit = require(&#39;express-rate-limit&#39;);

const loginLimiter = rateLimit(&#123;
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 10, // Limit each IP to 10 login requests per windowMs
  message: &#39;Too many login attempts from this IP, please try again later.&#39;
&#125;);

app.post(&#39;/login&#39;, loginLimiter, async (req, res) =&gt; &#123;
  const &#123; username, password &#125; = req.body;
  const user = await db.User.findOne(&#123; username &#125;);
  if (!user || user.password !== password) return res.status(401).send(&#39;Invalid credentials&#39;);
  res.send(&#39;Logged in&#39;);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">This effectively mitigates brute-force attempts and protects your authentication endpoint by throttling repeated access from the same IP address.</p><h2 class="heading" style="text-align:left;" id="injection-attacks"><b>Injection Attacks</b></h2><p class="paragraph" style="text-align:left;">Improperly validated inputs may lead to SQL, command, or script injection. This vulnerability is listed as OWASP API Security Top 10: API8 – Injection.</p><p class="paragraph" style="text-align:left;">Suppose we have a Node.js/Express API that takes user input and constructs a raw SQL query without any sanitization:</p><div class="codeblock"><pre><code>// INSECURE: Raw SQL query vulnerable to injection
app.get(&#39;/search&#39;, async (req, res) =&gt; &#123;
  const &#123; term &#125; = req.query;
  const results = await db.query(`SELECT * FROM products WHERE name LIKE &#39;%$&#123;term&#125;%&#39;`);
  res.json(results);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">If a user enters something like <code>%&#39; OR &#39;1&#39;=&#39;1</code>, this could result in the query:</p><div class="codeblock"><pre><code>SELECT * FROM products WHERE name LIKE &#39;%%&#39; OR &#39;1&#39;=&#39;1%&#39;</code></pre></div><p class="paragraph" style="text-align:left;">This would return <b>all products</b>, allowing attackers to extract unintended data.</p><h4 class="heading" style="text-align:left;" id="solution">Solution:</h4><p class="paragraph" style="text-align:left;">Use parameterized queries or an ORM that automatically escapes user input:</p><div class="codeblock"><pre><code>// SECURE: Parameterized query using query placeholders
app.get(&#39;/search&#39;, async (req, res) =&gt; &#123;
  const &#123; term &#125; = req.query;
  const results = await db.query(&#39;SELECT * FROM products WHERE name LIKE ?&#39;, [`%$&#123;term&#125;%`]);
  res.json(results);
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">Alternatively, if using an ORM like Sequelize:</p><div class="codeblock"><pre><code>const results = await Product.findAll(&#123;
  where: &#123;
    name: &#123;
      [Op.like]: `%$&#123;term&#125;%`
    &#125;
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">Always validate and sanitize user input. Never directly inject raw input into database queries, command shells, or other interpreters.</p><p class="paragraph" style="text-align:left;">That will be all for this newsletter issue. However, in the next one, we will cover the remaining 6 from the OWASP Top 10.</p><h2 class="heading" style="text-align:left;" id="key-principles-of-api-security">Key Principles of API Security</h2><ul><li><p class="paragraph" style="text-align:left;"><b>Authentication: </b>Ensure that only verified users or services can access the API. Use robust mechanisms such as OAuth 2.0, API keys, or JWT-based auth.</p></li><li><p class="paragraph" style="text-align:left;"><b>Authorization: </b>After authentication, verify what actions the user or client is permitted to perform. Implement role-based access control (RBAC) or attribute-based access control (ABAC).</p></li><li><p class="paragraph" style="text-align:left;"><b>Input Validation: </b>Sanitize and validate all input to prevent injection attacks and ensure data integrity.</p></li><li><p class="paragraph" style="text-align:left;"><b>Rate Limiting & Throttling: </b>Protect resources from abuse by capping the number of requests a client can make.</p></li><li><p class="paragraph" style="text-align:left;"><b>Data Encryption: </b>Use HTTPS/TLS to encrypt data in transit. For highly sensitive data, consider encrypting at rest as well.</p></li><li><p class="paragraph" style="text-align:left;"><b>Logging & Monitoring: </b>Track API access, failed logins, and anomalies. Use tools like Prometheus, Grafana, or ELK stack.</p></li><li><p class="paragraph" style="text-align:left;"><b>Versioning & Deprecation: </b>Avoid breaking changes by versioning APIs. Remove unused endpoints to reduce attack surface</p></li></ul><p class="paragraph" style="text-align:left;">APIs are essential to the architecture of modern software systems, but they also introduce new security risks. API security must be integrated from the earliest stages of design and remain a continuous practice throughout development and operation.</p><p class="paragraph" style="text-align:left;">From authentication and authorization to input validation and traffic monitoring, a comprehensive API security strategy not only protects data and services—it also ensures trust, reliability, and compliance.</p><p class="paragraph" style="text-align:left;">As APIs grow in number and complexity, so do the threats. Prioritize security, implement best practices, and choose the right tools to safeguard your API ecosystem.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-security" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=049b216e-7e97-45e3-9575-675c4a407477&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API &amp; API Design: API Documentation Tools</title>
  <description>This issue delves into the importance of API documentation tools, how they improve developer onboarding, and a comparison of popular tools such as Swagger (OpenAPI), DapperDox, Postman, and ReDoc.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-api-design-api-documentation-tools</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-api-design-api-documentation-tools</guid>
  <pubDate>Wed, 30 Apr 2025 17:45:36 +0000</pubDate>
  <atom:published>2025-04-30T17:45:36Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to landing your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 220 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-join-the-challenge"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Click here to join the challenge.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;" id="you-dont-need-to-be-technical-just-">You Don’t Need to Be Technical. Just Informed</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&redirect_to=https%3A%2F%2Fwww.theaireport.ai%2Fwelcome-page&redirect_delay=3&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_c88929d2-9213-45ed-8220-c91be203965b_65769d95&bhcl_id=75c9cc43-8fc3-4a34-ae7c-d56656d5f5ad_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/4d1c3ea6-ee41-40d1-8e57-312c2b3b85de/2.png?t=1748454279"/></a></div><p class="paragraph" style="text-align:left;">AI isn’t optional anymore—but coding isn’t required.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&redirect_to=https%3A%2F%2Fwww.theaireport.ai%2Fwelcome-page&redirect_delay=3&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_c88929d2-9213-45ed-8220-c91be203965b_65769d95&bhcl_id=75c9cc43-8fc3-4a34-ae7c-d56656d5f5ad_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The AI Report</a> gives business leaders the edge with daily insights, use cases, and implementation guides across ops, sales, and strategy.</p><p class="paragraph" style="text-align:left;">Trusted by professionals at Google, OpenAI, and Microsoft.</p><p class="paragraph" style="text-align:left;">👉 Get the newsletter and make smarter AI decisions.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&redirect_to=https%3A%2F%2Fwww.theaireport.ai%2Fwelcome-page&redirect_delay=3&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_c88929d2-9213-45ed-8220-c91be203965b_65769d95&bhcl_id=75c9cc43-8fc3-4a34-ae7c-d56656d5f5ad_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Lead with AI—no coding needed</a></p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">Documentation is important even in API and API Design.</p><p class="paragraph" style="text-align:left;">Therefore, writing clear and comprehensive documentation is as critical as the API development process itself.</p><p class="paragraph" style="text-align:left;">How many of you have experienced bad documentation for the API you want to use in your project? Do you remember how frustrating it was?</p><p class="paragraph" style="text-align:left;">If you have experienced it before, you can agree with me that bad API documentation hurts the developer experience of your API. That is why you need to plan out your API documentation correctly.</p><p class="paragraph" style="text-align:left;">This issue delves into the importance of API documentation tools, how they improve developer onboarding, and a comparison of popular tools such as <b>Swagger (OpenAPI), DapperDox, Postman, and ReDoc</b>.</p><h2 class="heading" style="text-align:left;" id="why-api-documentation-matters">Why API Documentation Matters</h2><p class="paragraph" style="text-align:left;">API documentation provides <b>a reference point for developers</b> on how to use the API effectively. Good documentation includes:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Endpoint definitions</b> (methods, URLs, request/response formats)</p></li><li><p class="paragraph" style="text-align:left;"><b>Authentication requirements</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Error codes and responses</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Example requests and responses</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Code samples in different languages</b></p></li></ul><p class="paragraph" style="text-align:left;">Without accurate and accessible documentation, even the most powerful API can become difficult to use. It’s the bridge between your backend logic and the developers consuming your services.</p><p class="paragraph" style="text-align:left;">Next, if you’re looking at choosing and integrating a documentation tool into your API workflow. You need to understand what makes a good documentation tool and how each of these tools is different in its unique way.</p><h2 class="heading" style="text-align:left;" id="what-makes-a-good-documentation-too">What makes a Good Documentation Tool?</h2><p class="paragraph" style="text-align:left;">An ideal API documentation tool should:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Support auto-generation</b> from code or API definitions (e.g., OpenAPI specs).</p></li><li><p class="paragraph" style="text-align:left;">Offer a <b>searchable, user-friendly interface.</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Allow interactive testing</b> (try-it-out functionality).</p></li><li><p class="paragraph" style="text-align:left;">Be <b>customizable and themeable.</b></p></li><li><p class="paragraph" style="text-align:left;">Enable <b>version control and change tracking.</b></p></li><li><p class="paragraph" style="text-align:left;">Provide support for <b>multi-language code samples.</b></p></li></ul><p class="paragraph" style="text-align:left;">Looking at these features, you see that I am only interested in the idea features that truly matter in a documentation tool and not the features of individual tools, because I want you to pick any tool of your choice, knowing exactly what you want in it.</p><h2 class="heading" style="text-align:left;" id="popular-api-documentation-tools">Popular API Documentation Tools</h2><p class="paragraph" style="text-align:left;">Now that we know what we truly want in a documentation tool, let’s explore some of the popular ones and share some of their features to help you choose a tool that will streamline your API development and management workflow.</p><p class="paragraph" style="text-align:left;">Please note that I am not affiliated with any of these tools.</p><ul><li><p class="paragraph" style="text-align:left;"><b>Swagger</b></p></li><li><p class="paragraph" style="text-align:left;"><b>DapperDox</b></p></li><li><p class="paragraph" style="text-align:left;"><b>ReDoc</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Postman</b></p></li></ul><h3 class="heading" style="text-align:left;" id="swagger-ui-open-api">Swagger UI (OpenAPI)</h3><p class="paragraph" style="text-align:left;"><b>Swagger</b> is one of the most widely adopted API documentation ecosystems and the de facto standard for OpenAPI documentation. Let’s look at some of the key features of Swagger:</p><ul><li><p class="paragraph" style="text-align:left;">Reads from an OpenAPI (formerly Swagger) spec in YAML/JSON</p></li><li><p class="paragraph" style="text-align:left;">Auto-generates interactive API documentation</p></li><li><p class="paragraph" style="text-align:left;">Try-it-out feature for real-time testing</p></li><li><p class="paragraph" style="text-align:left;">Broad community support and tooling ecosystem</p></li></ul><p class="paragraph" style="text-align:left;">Swagger, as a documentation tool, cannot solve all the problems. However, it is best for REST APIs, quick and interactive documentation.</p><p class="paragraph" style="text-align:left;">Below is a simple example of how documentations are generated with Swagger:</p><div class="codeblock"><pre><code>paths:
  /users:
    get:
      summary: Retrieve users
      responses:
        &#39;200&#39;:
          description: A list of users
</code></pre></div><p class="paragraph" style="text-align:left;">Swagger will turn the code snippet above into an interactive, clickable interface. Swagger and Postman are my personal favourites, and I have used them in countless backend projects.</p><h3 class="heading" style="text-align:left;" id="dapper-dox">DapperDox</h3><p class="paragraph" style="text-align:left;"><b>DapperDox</b> goes beyond rendering OpenAPI documentation by integrating <b>documentation portals</b> and <b>Markdown pages</b> for narratives. Below are some of the key features of DapperDox:</p><ul><li><p class="paragraph" style="text-align:left;">Combines OpenAPI specs with user guides and tutorials</p></li><li><p class="paragraph" style="text-align:left;">Extensible layout with Markdown integration</p></li><li><p class="paragraph" style="text-align:left;">API versioning and changelogs</p></li><li><p class="paragraph" style="text-align:left;">Offers a static site output for hosting</p></li></ul><p class="paragraph" style="text-align:left;">I haven’t personally used this tool before, but from research, it is best for enterprise-grade documentation portals with extra narrative content.</p><h2 class="heading" style="text-align:left;" id="re-doc">ReDoc</h2><p class="paragraph" style="text-align:left;"><b>ReDoc</b> is another OpenAPI-powered tool focused on simplicity and beautiful, responsive documentation. Let’s explore some of the key features of ReDoc.</p><ul><li><p class="paragraph" style="text-align:left;">Fully customizable with CSS and branding</p></li><li><p class="paragraph" style="text-align:left;">Supports deep linking and markdown</p></li><li><p class="paragraph" style="text-align:left;">Performance-optimized for large APIs</p></li><li><p class="paragraph" style="text-align:left;">Minimalist, clean UI ideal for production docs</p></li></ul><p class="paragraph" style="text-align:left;">ReDoc is a great open-source tool that is best for public-facing APIs where branding and UX matter.</p><h2 class="heading" style="text-align:left;" id="postman">Postman</h2><p class="paragraph" style="text-align:left;"><b>Postman</b> is a popular API platform known primarily for API testing, but it also offers a feature-rich documentation system that integrates tightly with collections. If you’ve been building APIs, you should already know Postman and some of the key features as listed below:</p><ul><li><p class="paragraph" style="text-align:left;">Auto-generates docs from Postman collections</p></li><li><p class="paragraph" style="text-align:left;">Interactive documentation with embedded testing</p></li><li><p class="paragraph" style="text-align:left;">Supports Markdown descriptions</p></li><li><p class="paragraph" style="text-align:left;">Collaboration features and versioning</p></li><li><p class="paragraph" style="text-align:left;">Public or private sharing of docs</p></li></ul><p class="paragraph" style="text-align:left;">Postman is a suite of API testing and management tools best for teams who want seamless documentation generation without writing OpenAPI manually.</p><h2 class="heading" style="text-align:left;" id="how-to-choose-the-right-tool">How to Choose the Right Tool</h2><p class="paragraph" style="text-align:left;">Choosing the right documentation tool to streamline your API development can be difficult because of the numerous tools available. However, here are factors to consider:</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/8d1bf53d-add2-4bf7-b7fc-f4a1c105da9c/image.png?t=1746034521"/><div class="image__source"><span class="image__source_text"><p>How to Choose the Right Tool</p></span></div></div><p class="paragraph" style="text-align:left;">API documentation tools are no longer optional; they are fundamental to <b>delivering an exceptional developer experience</b>. Whether you’re a solo backend engineer or a large API-first team, if you can choose the right documentation tool, it will help your API speak clearly and confidently to the world.</p><h3 class="heading" style="text-align:left;" id="just-to-add">Just to add:</h3><p id="if-you-want-to-go-deeper-into-docum" class="paragraph" style="text-align:left;">If you want to go deeper into Documentation Engineering, I have created a complete roadmap course that is focused on engineers like you and walks you through how to become a great documentation engineer.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://technicalwriterhq.com/documentation-engineering-for-developers/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Check it out here.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-api-documentation-tools" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=0acb11fc-556c-4dba-acd4-078ce7e646a4&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: API Keys &amp; Management</title>
  <description>In today’s issue, we will explore the concept of API Keys, how they function, and the role of API Management in maintaining security and performance in API design.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-api-keys-management</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-api-keys-management</guid>
  <pubDate>Tue, 29 Apr 2025 19:05:01 +0000</pubDate>
  <atom:published>2025-04-29T19:05:01Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to landing your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 220 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-join-the-challenge"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Click here to join the challenge.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;">Start learning AI in 2025</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_f1c01c77-9b05-45c8-8424-93054edd017b_d22f5b49&bhcl_id=c2c464bc-96b1-45d1-bd0c-df433d17693d_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/3063de3b-8243-4e98-bb10-581679f4b033/Learn_AI_in_3_Minutes_Beehive__1_.jpg?t=1739301904"/></a></div><p class="paragraph" style="text-align:left;">Keeping up with AI is hard – we get it!</p><p class="paragraph" style="text-align:left;">That’s why over 1M professionals read <a class="link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_f1c01c77-9b05-45c8-8424-93054edd017b_d22f5b49&bhcl_id=c2c464bc-96b1-45d1-bd0c-df433d17693d_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Superhuman AI</a> to stay ahead.</p><ul><li><p class="paragraph" style="text-align:left;">Get daily AI news, tools, and tutorials</p></li><li><p class="paragraph" style="text-align:left;">Learn new AI skills you can use at work in 3 mins a day</p></li><li><p class="paragraph" style="text-align:left;">Become 10X more productive</p></li></ul><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_f1c01c77-9b05-45c8-8424-93054edd017b_d22f5b49&bhcl_id=c2c464bc-96b1-45d1-bd0c-df433d17693d_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up and start mastering AI</a></p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">APIs form the backbone of data exchange and service integration across web, mobile, and cloud-based systems. However, it is paramount to ensure that APIs are accessed securely and responsibly.</p><p class="paragraph" style="text-align:left;">Therefore, to ensure that this is achieved, there are two central elements to understand, viz:</p><ul><li><p class="paragraph" style="text-align:left;">API Keys</p></li><li><p class="paragraph" style="text-align:left;">API Management</p></li></ul><p class="paragraph" style="text-align:left;">In today’s issue, we will explore the concept of API Keys, how they function, and the role of API Management in maintaining security and performance in API design.</p><h2 class="heading" style="text-align:left;" id="what-is-an-api-key">What is an API Key?</h2><p class="paragraph" style="text-align:left;">An API key is a unique string generated by the API provider to authenticate and identify the calling program, developer, or application requesting access to the API. It acts as a simple form of authentication and is typically included in request headers, query strings, or body payloads.</p><div class="codeblock"><pre><code>GET /api/v1/weather?city=London
Host: api.example.com
x-api-key: abc123xyz456</code></pre></div><p class="paragraph" style="text-align:left;">The snippet above passes a simple <code>x-api-key</code> to the request. API Keys are simple to generate and use, uniquely associated with users or applications, used to monitor and control usage (e.g., rate limits, quotas), and often the first layer of security before deeper authentication mechanisms.</p><p class="paragraph" style="text-align:left;">If you’ve built an API before, you may have requested that your frontend engineers always pass either a JWT or a normal token to validate an authenticated user. Now, that is an example of one kind of API Key that could be passed.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/eee8ed14-cbcb-4184-9913-f59e64343549/ChatGPT_Image_Apr_29__2025__07_38_39_PM.png?t=1745951955"/></div><p class="paragraph" style="text-align:left;">Next, let’s explore some benefits and limitations of API keys in API design:</p><h3 class="heading" style="text-align:left;" id="benefits-of-api-keys">Benefits of API Keys</h3><p class="paragraph" style="text-align:left;">Despite being a basic method, API keys provide several essential advantages:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Access Control:</b> You can issue unique API keys per client and revoke or regenerate them if needed.</p></li><li><p class="paragraph" style="text-align:left;"><b>Rate Limiting & Quotas:</b> Each key can be tied to specific usage limits, preventing service abuse or overuse.</p></li><li><p class="paragraph" style="text-align:left;"><b>Monitoring & Analytics:</b> Issuing individual keys to specific users can help track usage patterns, popular endpoints, and detect anomalies on a per-key basis.</p></li><li><p class="paragraph" style="text-align:left;"><b>Simplicity:</b> No complex authentication handshake—making API keys great for internal systems or simple integrations.</p></li></ul><p class="paragraph" style="text-align:left;">Limitations of API Keys</p><p class="paragraph" style="text-align:left;">Sometimes, API keys can also have significant security limitations:</p><ul><li><p class="paragraph" style="text-align:left;">They do not verify the identity of the end user.</p></li><li><p class="paragraph" style="text-align:left;">API keys are static and, if leaked, can be easily misused.</p></li><li><p class="paragraph" style="text-align:left;">They are often transmitted in plaintext unless HTTPS is enforced.</p></li></ul><p class="paragraph" style="text-align:left;">Therefore, while useful, API keys are often combined with more secure methods such as OAuth or JWT in production-grade systems.</p><p class="paragraph" style="text-align:left;">Moving on, let’s look at API Management to understand the set of practices used to design and scale APIs.</p><h2 class="heading" style="text-align:left;" id="what-is-api-management">What is API Management?</h2><p class="paragraph" style="text-align:left;">API Management refers to the comprehensive set of practices, policies, and tools that organizations use to design, deploy, secure, monitor, and scale APIs throughout their lifecycle.</p><p class="paragraph" style="text-align:left;">Below are some of the key responsibilities of API Management:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Design & Development:</b> This stage involves the design and development of the API, and tools such as Swagger or Postman help in designing APIs with standardized specifications.</p></li><li><p class="paragraph" style="text-align:left;"><b>Security Enforcement:</b> API Management involves managing authentication (API Keys, OAuth, JWT), encryption (HTTPS), IP whitelisting, and rate limiting.</p></li><li><p class="paragraph" style="text-align:left;"><b>Monitoring and Analytics: </b>This involves capturing API usage statistics, error rates, latency, and client behavior.</p></li><li><p class="paragraph" style="text-align:left;"><b>Versioning & Lifecycle Management:</b> Handling changes in APIs (e.g., v1 to v2), deprecations, backward compatibility, and changelogs.</p></li><li><p class="paragraph" style="text-align:left;"><b>Developer Experience:</b> Offering developer portals with documentation, testing consoles, key management, and sandbox environments.</p></li></ul><p class="paragraph" style="text-align:left;">Everything mentioned above and more make up the API Management. Here’s a simplified diagram showing how API keys integrate within the broader context of API management:</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/6d8393b1-6976-4250-99cf-2741f2b1cad0/image.png?t=1745952565"/></div><h3 class="heading" style="text-align:left;" id="api-management-tools">API Management Tools</h3><p class="paragraph" style="text-align:left;">Several platforms provide comprehensive API management capabilities, and below are the common platforms you can check out.</p><div class="section" style="background-color:transparent;margin:0.0px 0.0px 0.0px 0.0px;padding:0.0px 0.0px 0.0px 0.0px;"><div style="padding:14px 15px 14px;"><table class="bh__table" width="100%" style="border-collapse:collapse;"><tr class="bh__table_row"><th class="bh__table_header" width="50%"><p class="paragraph" style="text-align:left;">Tools</p></th><th class="bh__table_header" width="50%"><p class="paragraph" style="text-align:left;">Features</p></th></tr><tr class="bh__table_row"><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Kong</p></td><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Open-source gateway, plugins for rate limiting, logging</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Apigee (Google) </p></td><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Enterprise-grade, full lifecycle management</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">AWS API Gateway </p></td><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Integration with AWS IAM, Lambda, and monitoring tools</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Postman</p></td><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Primarily for design/testing, but includes key generation</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Azure API Management</p></td><td class="bh__table_cell" width="50%"><p class="paragraph" style="text-align:left;">Scalable, secure, integrates with Azure AD, and provides insights</p></td></tr></table></div></div><p class="paragraph" style="text-align:left;">Furthermore, let’s look at some of the best practices you can implement when building out your API Keys and Management pipeline.</p><ul><li><p class="paragraph" style="text-align:left;"><b>Always use HTTPS</b> to prevent key exposure over the network.</p></li><li><p class="paragraph" style="text-align:left;"><b>Rotate keys regularly</b> to reduce long-term exposure.</p></li><li><p class="paragraph" style="text-align:left;"><b>Limit permissions</b> per key (least privilege principle).</p></li><li><p class="paragraph" style="text-align:left;"><b>Use environment-based keys</b> (e.g., different keys for dev, test, prod).</p></li><li><p class="paragraph" style="text-align:left;"><b>Implement IP restrictions</b> to limit access from specific sources.</p></li><li><p class="paragraph" style="text-align:left;"><b>Monitor and alert</b> on unusual API usage patterns.</p></li></ul><p class="paragraph" style="text-align:left;">API keys offer a lightweight mechanism for securing access to APIs, but they’re best suited for low-risk or internal use cases. For robust security, they should be part of a <b>broader API management strategy</b> that includes access control, monitoring, rate limiting, and lifecycle governance.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2b0f43ef-98bb-4e20-8849-0a2710afeaf2/ChatGPT_Image_Apr_29__2025__07_59_55_PM.png?t=1745953294"/><div class="image__source"><span class="image__source_text"><p>Rate limiting per API Key</p></span></div></div><p class="paragraph" style="text-align:left;">API management platforms empower organizations to deliver high-quality APIs with agility, while keeping access secure, usage optimized, and developers productive.</p><p class="paragraph" style="text-align:left;">As API ecosystems grow in complexity and scale, mastering both <b>API key usage</b> and <b>API management practices</b> becomes essential for backend engineers, developers, or architects designing modern software solutions.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-api-keys-management" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=ab549b66-8fed-4a5b-838f-31ccd36f4e26&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API &amp; API Design: Authorization Methods</title>
  <description>This issue explores the most widely adopted authorization methods in API design, detailing how they work, when to use them, and how to implement them securely.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-api-design-authorization-methods</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-api-design-authorization-methods</guid>
  <pubDate>Sun, 27 Apr 2025 12:12:00 +0000</pubDate>
  <atom:published>2025-04-27T12:12:00Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to landing your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 220 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-join-the-challenge"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Click here to join the challenge.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;">Find out why 1M+ professionals read Superhuman AI daily.</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_2c5697f2-be54-4c5e-9101-2613cb6946d7_d22f5b49&bhcl_id=9d232ebd-2127-497f-bfa7-a55d87b7f2ba_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/1a894cae-ce4b-4849-8426-d978ddb6a887/Learn_AI_in_3_Minutes_Beehive.jpg?t=1739301736"/></a></div><p class="paragraph" style="text-align:left;">In 2 years you will be working for AI </p><p class="paragraph" style="text-align:left;">Or an AI will be working for you</p><p class="paragraph" style="text-align:left;">Here&#39;s how you can future-proof yourself:</p><ol start="1"><li><p class="paragraph" style="text-align:left;">Join the <a class="link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_2c5697f2-be54-4c5e-9101-2613cb6946d7_d22f5b49&bhcl_id=9d232ebd-2127-497f-bfa7-a55d87b7f2ba_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Superhuman AI</a> newsletter – read by 1M+ people at top companies</p></li><li><p class="paragraph" style="text-align:left;">Master AI tools, tutorials, and news in just 3 minutes a day</p></li><li><p class="paragraph" style="text-align:left;">Become 10X more productive using AI</p></li></ol><p class="paragraph" style="text-align:left;">Join 1,000,000+ pros at companies like Google, Meta, and Amazon that are using AI to get ahead.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/faa6a747-8c1c-43c1-8155-91aa43268f01?email={{email}}&redirect_to=https%3A%2F%2Fwww.superhuman.ai%2Fc%2Fconfirmation%3Fmagiclink_subscription&utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&redirect_delay=3&_bhiiv=opp_2c5697f2-be54-4c5e-9101-2613cb6946d7_d22f5b49&bhcl_id=9d232ebd-2127-497f-bfa7-a55d87b7f2ba_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up and start learning AI</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In our previous issue, <a class="link" href="https://newsletter.masteringbackend.com/p/api-api-design-authentication-methods?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">&quot;Authentication Methods in API Design</a>,&quot; we explored the most widely adopted authentication methods in API design, detailing how they work, when to use them, and how to implement them securely.</p><p class="paragraph" style="text-align:left;">This issue explores API design&#39;s most widely adopted authorization methods, detailing how they work, when to use them, and how to implement them securely.</p><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">In API design, ensuring that authenticated users only access the resources they are permitted to access is just as important as verifying who they are. This is where <b>authorization</b> comes in. </p><p class="paragraph" style="text-align:left;">While <b>authentication</b> answers the &quot;<b>Who are you?</b>&quot; <b>authorization</b> asks, &quot;<b>What are you allowed to do?</b>&quot;</p><p class="paragraph" style="text-align:left;">Authorization methods form the backbone of secure access control in APIs. They enforce rules that determine which clients—whether users, services, or applications—can access what data and perform what actions. This is essential for protecting sensitive information, preserving data integrity, and ensuring business logic is correctly enforced.</p><p class="paragraph" style="text-align:left;">This issue explores key authorization methods in API design, how they function, and when to use each based on security, scalability, and user experience considerations.</p><h2 class="heading" style="text-align:left;" id="authorization-vs-authentication">Authorization vs. Authentication</h2><p class="paragraph" style="text-align:left;">Before diving into the various methods, it’s important to distinguish <b>authentication</b> from <b>authorization</b>:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Authentication</b> verifies <b>who</b> a user or application is.</p></li><li><p class="paragraph" style="text-align:left;"><b>Authorization</b> verifies <b>what</b> they can access or do.</p></li></ul><p class="paragraph" style="text-align:left;">While often used together, they serve distinct purposes and require different implementation strategies.</p><h2 class="heading" style="text-align:left;" id="role-based-access-control-rbac">Role-Based Access Control (RBAC)</h2><p class="paragraph" style="text-align:left;"><b>RBAC</b> assigns permissions to users based on their role within an organization. For example, a user with an &quot;Admin&quot; role may have access to more resources than a &quot;Viewer&quot;.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/5bc744c5-cbf7-4a6b-ab80-ac53c454ca8c/ChatGPT_Image_Apr_25__2025__11_14_58_AM.png?t=1745667314"/><div class="image__source"><span class="image__source_text"><p>Role-Based Access Control (RBAC)</p></span></div></div><p class="paragraph" style="text-align:left;">Roles are defined at the system level, and each role has predefined privileges. When a user is authenticated, the API checks their assigned role and determines whether they are authorized to perform the requested action.</p><h3 class="heading" style="text-align:left;" id="how-it-works">How it Works</h3><ol start="1"><li><p class="paragraph" style="text-align:left;">Users are assigned roles (e.g., Admin, Editor, Viewer).</p></li><li><p class="paragraph" style="text-align:left;">Each role is mapped to a set of permissions.</p></li><li><p class="paragraph" style="text-align:left;">The API checks the user’s role on each request and determines whether the action is allowed.</p></li></ol><p class="paragraph" style="text-align:left;">For example, a customer support agent needs access to user account information but does not require administrative control over system settings, whereas a system administrator does.</p><p class="paragraph" style="text-align:left;">All RBAC models include the following core elements:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Administrators</b>: Users responsible for defining roles and assigning permissions.</p></li><li><p class="paragraph" style="text-align:left;"><b>Roles</b>: Groups of users categorized by the tasks or responsibilities they perform.</p></li><li><p class="paragraph" style="text-align:left;"><b>Permissions</b>: Each role is granted specific actions and access levels, which determine what users in that role are allowed to do.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Role-Based Access Control (RBAC)</b> enables administrators to create roles, assign users to them, and manage permissions to control access within a system.</p><div class="codeblock"><pre><code>if (req.user.role !== &#39;admin&#39;) &#123;
  return res.status(403).send(&#39;Forbidden: Admins only&#39;);
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">Role-based access control is best for Enterprise systems with well-defined roles and Multi-user platforms like CMSs or SaaS apps.</p><h2 class="heading" style="text-align:left;" id="attribute-based-access-control-abac">Attribute-Based Access Control (ABAC)</h2><p class="paragraph" style="text-align:left;"><b>ABAC</b> controls access using attributes rather than roles. These attributes can include user details (e.g., department, clearance level), resource metadata, or environmental conditions (e.g., time of day).</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2b26640d-2c5f-42ec-9e1c-9d345e88e2ec/ChatGPT_Image_Apr_26__2025__12_37_20_PM.png?t=1745673341"/><div class="image__source"><span class="image__source_text"><p>Attribute-Based Access Control (ABAC)</p></span></div></div><p class="paragraph" style="text-align:left;">ABAC is highly flexible and supports complex access policies.</p><h3 class="heading" style="text-align:left;" id="how-it-works">How it Works</h3><ol start="1"><li><p class="paragraph" style="text-align:left;">Define attributes for users, resources, and environment.</p></li><li><p class="paragraph" style="text-align:left;">Create policies based on combinations of these attributes.</p></li><li><p class="paragraph" style="text-align:left;">Evaluate each request against the relevant policy.</p></li></ol><div class="codeblock"><pre><code>if (req.user.department === &#39;finance&#39; &amp;&amp; req.resource.type === &#39;report&#39;) &#123;
  // allow access
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">The attribute-based access control is best for fine-grained and dynamic access control and scenarios with many user-resource-environment combinations.</p><h2 class="heading" style="text-align:left;" id="conclusion">Conclusion</h2><p class="paragraph" style="text-align:left;">Properly implemented authorization is essential to any API&#39;s security architecture. Whether you’re designing internal APIs or exposing functionality to third parties, choosing the right authorization strategy ensures that only permitted actors can perform certain operations.</p><ul><li><p class="paragraph" style="text-align:left;"><b>RBAC</b> offers straightforward, role or resource-based permissions.</p></li><li><p class="paragraph" style="text-align:left;"><b>ABAC</b> allows for highly dynamic and context-aware access policies.</p></li></ul><p class="paragraph" style="text-align:left;">As your application grows, so do your authorization needs. Consider starting with a simple RBAC model and evolving toward ABAC as complexity increases. Whichever method you choose, ensure it is consistently enforced across your API ecosystem.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authorization-methods" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p><p class="paragraph" style="text-align:left;"></p><p class="paragraph" style="text-align:left;"></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=dd1ce5eb-aaed-4c5f-8d9e-4a77642038ae&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>[New Podcast]: Rust + AWS Lambda: The Power of Serverless Performance</title>
  <description>In this podcast, Luciano shares his experience with Rust and AWS Lambda and how they interact. He provides practical examples of building Rust applications and deploying them to AWS Lambda.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/caba3e49-aaae-4f23-88b6-67d8ab13c06a/asfdas__5_.png" length="279925" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/new-podcast-rust-aws-lambda-the-power-of-serverless-performance</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/new-podcast-rust-aws-lambda-the-power-of-serverless-performance</guid>
  <pubDate>Wed, 16 Apr 2025 09:30:57 +0000</pubDate>
  <atom:published>2025-04-16T09:30:57Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Podcast]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>Easter Offer: 60% Off All Backend Engineering Courses</b></p><p class="paragraph" style="text-align:left;">This Easter, we offer a rare opportunity to accelerate your backend engineering journey.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/e8fca60e-e330-4e00-8d46-c16d811d93ab/ChatGPT_Image_Apr_16__2025__09_21_25_AM.png?t=1744792683"/><div class="image__source"><span class="image__source_text"><p>Easter Offer: 60% Off All Backend Engineering Courses</p></span></div></div><p class="paragraph" style="text-align:left;">For a limited time only, you can access <b>any course on Masteringbackend at 60% off</b>. Whether you&#39;re just starting or looking to deepen your expertise, our curated backend engineering tracks are built to help you go beyond tutorials and build real-world skills.</p><p class="paragraph" style="text-align:left;"><b>What You’ll Get With Every Course:</b></p><ul><li><p class="paragraph" style="text-align:left;">Hands-on projects based on real-world backend scenarios</p></li><li><p class="paragraph" style="text-align:left;">Comprehensive tracks for Python, Node.js, Rust, Java, and more</p></li><li><p class="paragraph" style="text-align:left;">Complete backend job preparation kits</p></li><li><p class="paragraph" style="text-align:left;">Mock interviews, resume reviews, and career support</p></li><li><p class="paragraph" style="text-align:left;">A private community of backend engineers and mentors</p></li><li><p class="paragraph" style="text-align:left;">Certificates of completion to validate your skills</p></li></ul><p class="paragraph" style="text-align:left;">Thousands of developers have used our platform to build real projects, master backend fundamentals, and land roles at top companies.</p><p class="paragraph" style="text-align:left;">Now it’s your turn—at a fraction of the cost.</p><p class="paragraph" style="text-align:left;"><b>Limited Access. The promo code below is only for the first 20 people to use it. Secure your access at 60% off before the offer expires in 72 hours.</b></p><h1 class="heading" style="text-align:left;" id="visit-course-catalog-use-easter-60"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Visit the Course Catalog. Use “EASTER60”</a></h1><hr class="content_break"><p class="paragraph" style="text-align:left;">What happens when you combine the speed and safety of <b>Rust</b> with the scalability of <b>AWS Lambda</b>?</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/b4c0d0d7-f5cd-4970-a198-7fe0444fb356/asfdas__5_.png?t=1744794904"/></div><p class="paragraph" style="text-align:left;">I recently sat down with <b>Luciano Mammino</b>, Senior Architect and the brilliant mind behind the bestselling book <i>on </i><a class="link" href="https://www.nodejsdesignpatterns.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow"><i>“Node.js Design Patterns,”</i></a> to find out — and the result is one of the most insightful podcast episodes we’ve ever recorded.</p><p class="paragraph" style="text-align:left;">Watch now → <a class="link" href="https://www.youtube.com/watch?v=Zqi-zRoTErI&ab_channel=SolomonEseme&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Rust + AWS Lambda: The Power of Serverless Performance</a></p><h3 class="heading" style="text-align:left;" id="in-this-episode-we-dive-deep-into">In this episode, we dive deep into:</h3><ul><li><p class="paragraph" style="text-align:left;"><b>Why Rust is a hidden gem for backend developers: </b>Luciano explains how Rust’s performance, safety, and type system make it a top-tier language for serious backend work.</p></li><li><p class="paragraph" style="text-align:left;"><b>The magic of Rust + Lambda: </b>Discover how smaller binaries and lightning-fast cold starts can <b>dramatically lower your cloud costs</b> — without sacrificing speed or reliability.</p></li><li><p class="paragraph" style="text-align:left;"><b>Real-world tradeoffs: </b>We talk honestly about Rust’s steeper learning curve and smaller ecosystem, and how to navigate it effectively.</p></li><li><p class="paragraph" style="text-align:left;"><b>Best practices for shipping production-grade Rust Lambdas: </b>From using <b>Infrastructure as Code</b> to deploying with <b>Cargo Lambda</b>, Luciano walks us through his battle-tested workflows.</p></li><li><p class="paragraph" style="text-align:left;"><b>Live coding session: </b>Yes — you’ll <b>see me scaffold, test, and deploy a real Lambda function using Rust</b> in minutes.</p></li></ul><p class="paragraph" style="text-align:left;">If you&#39;re a backend engineer, cloud architect, or just curious about <b>Rust in the real world</b>, this episode is a <b>must-watch</b>.</p><p class="paragraph" style="text-align:left;">Watch the full episode now → <a class="link" href="https://www.youtube.com/watch?v=Zqi-zRoTErI&ab_channel=SolomonEseme&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Click here</a></p><p class="paragraph" style="text-align:left;">Whether you’re thinking of picking up Rust, exploring serverless, or looking to level up your backend engineering skills, this episode is packed with insights, practical examples, and powerful takeaways.</p><p class="paragraph" style="text-align:left;">Let me know what you think after you watch it, and don’t forget to subscribe if you want more conversations like this in your feed.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 60% discount on any of these courses for this easter. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=new-podcast-rust-aws-lambda-the-power-of-serverless-performance" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p><p class="paragraph" style="text-align:left;"></p><p class="paragraph" style="text-align:left;"></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=d6ba445b-7e50-4326-a867-b4fa4976f272&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API &amp; API Design: Authentication Methods</title>
  <description>This issue explores the API design&#39;s most widely adopted authentication methods, detailing how they work, when to use them, and how to implement them securely.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-api-design-authentication-methods</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-api-design-authentication-methods</guid>
  <pubDate>Sat, 12 Apr 2025 16:30:00 +0000</pubDate>
  <atom:published>2025-04-12T16:30:00Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 220 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-join-the-challenge"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Click here to join the challenge.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;">Start learning AI in 2025</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_5f50d505-ec0c-4e64-a71c-9683de33dcab_e4221c46&bhcl_id=37084def-b408-4eba-a83e-cd11801be1dd_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/f58a9eaf-b0c9-44d2-b0f4-a4507e19576c/Banner_2.png?t=1732571346"/></a></div><p class="paragraph" style="text-align:left;">Everyone talks about AI, but no one has the time to learn it. So, we found the easiest way to learn AI in as little time as possible: <a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_5f50d505-ec0c-4e64-a71c-9683de33dcab_e4221c46&bhcl_id=37084def-b408-4eba-a83e-cd11801be1dd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The Rundown AI.</a></p><p class="paragraph" style="text-align:left;">It&#39;s a free AI newsletter that keeps you up-to-date on the latest AI news, and teaches you how to apply it in just 5 minutes a day.</p><p class="paragraph" style="text-align:left;">Plus, complete the quiz after signing up and they’ll recommend the best AI tools, guides, and courses – tailored to your needs.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_5f50d505-ec0c-4e64-a71c-9683de33dcab_e4221c46&bhcl_id=37084def-b408-4eba-a83e-cd11801be1dd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up to start learning.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In our previous issue on <a class="link" href="https://newsletter.masteringbackend.com/p/error-handling-in-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Error handling in API Design</a>, we explored best practices for API error handling, structured error responses, and implemented a robust error-handling system in a RESTful API using Node.js and Express.</p><p class="paragraph" style="text-align:left;">This issue explores the API design&#39;s most widely adopted authentication methods, detailing how they work, when to use them, and how to implement them securely.</p><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">Application Programming Interfaces (APIs) are fundamental components of modern software systems, enabling applications to communicate, share data, and perform operations programmatically. </p><p class="paragraph" style="text-align:left;">As APIs expose system functionality to external clients, ensuring secure access becomes imperative. One of the foundational elements of API security is authentication, the process by which an API verifies the identity of the client making a request.</p><p class="paragraph" style="text-align:left;">Authentication ensures that the right users or applications have access to the correct resources. Several authentication methods exist, each designed to serve particular use cases, security levels, and architectural requirements. </p><ul><li><p class="paragraph" style="text-align:left;">Basic Authentication</p></li><li><p class="paragraph" style="text-align:left;">API Key Authentication</p></li><li><p class="paragraph" style="text-align:left;">Token-Based Authentication</p></li><li><p class="paragraph" style="text-align:left;">JWT (JSON Web Tokens)</p></li><li><p class="paragraph" style="text-align:left;">OAuth 2.0 Authentication</p></li><li><p class="paragraph" style="text-align:left;">Session-based Authentication</p></li></ul><p class="paragraph" style="text-align:left;">Above are a few authentication methods that we will explore in great detail in upcoming newsletter episodes.</p><p class="paragraph" style="text-align:left;">However, we will briefly examine each authentication method to gain a general understanding of the various methods available for API design.</p><h2 class="heading" style="text-align:left;" id="basic-authentication">Basic Authentication</h2><p class="paragraph" style="text-align:left;">Basic Authentication is one of the earliest and simplest authentication mechanisms. In this approach, the client sends the username and password encoded in Base64 as part of the HTTP <code>Authorization</code> header with every request. Although simple to implement, Basic Authentication has significant security limitations.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/72d911f0-c799-49bf-b4bf-10ed075c9512/ChatGPT_Image_Apr_12__2025__11_26_46_AM.png?t=1744457367"/><div class="image__source"><span class="image__source_text"><p>Basic Authentication</p></span></div></div><p class="paragraph" style="text-align:left;">Since the credentials are sent with every request, this method is highly susceptible to interception and should never be used without HTTPS. Basic Authentication is best suited for internal or low-risk APIs where more robust security measures may not be necessary.</p><div class="codeblock"><pre><code>app.use((req, res, next) =&gt; &#123;
  const authHeader = req.headers.authorization;
  if (!authHeader) return res.status(401).send(&#39;Missing Authorization header&#39;);

  const base64Credentials = authHeader.split(&#39; &#39;)[1];
  const credentials = Buffer.from(base64Credentials, &#39;base64&#39;).toString(&#39;ascii&#39;);
  const [username, password] = credentials.split(&#39;:&#39;);

  if (username === &#39;admin&#39; &amp;&amp; password === &#39;secret&#39;) &#123;
    next();
  &#125; else &#123;
    res.status(401).send(&#39;Unauthorized&#39;);
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">This code snippet demonstrates Express.js middleware that checks if the username and password are correct for incoming secured requests. The middleware will be added to all secured endpoints to make sure the correct user can access the endpoint.</p><h2 class="heading" style="text-align:left;" id="api-key-authentication">API Key Authentication</h2><p class="paragraph" style="text-align:left;">API Key Authentication involves issuing a unique identifier to each client. This key is included in each request, typically as a query parameter or in a custom header, such as <code>x-api-key</code>. The server checks the key against a database or configuration file and grants access if the key is valid.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/ed192448-14e3-46e3-a6d7-77fa4c2aa9e7/ChatGPT_Image_Apr_12__2025__11_26_45_AM.png?t=1744457417"/><div class="image__source"><span class="image__source_text"><p>Token-Based Authentication</p></span></div></div><p class="paragraph" style="text-align:left;">While easy to implement and widely supported, API keys do not provide information about the client&#39;s identity beyond the key itself. They are static, do not expire automatically, and can be easily leaked if not carefully protected. Nevertheless, they are suitable for server-to-server communication and third-party integrations where simplicity is preferred.</p><div class="codeblock"><pre><code>app.use((req, res, next) =&gt; &#123;
  const apiKey = req.headers[&#39;x-api-key&#39;];
  if (apiKey !== process.env.MY_API_KEY) &#123;
    return res.status(403).send(&#39;Forbidden&#39;);
  &#125;
  next();
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">This code snippet uses Express middleware to check if the request header contains an API key and if the code is equal to the one saved on the server. If true, give access if not, return an error.</p><h2 class="heading" style="text-align:left;" id="token-based-authentication">Token-Based Authentication</h2><p class="paragraph" style="text-align:left;">Token-based authentication improves upon API key authentication by issuing a token to the client after a successful login. This token, usually included in the <code>Authorization</code> header as a Bearer token, is then used to authenticate future requests.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/4f74f7e5-c924-4b13-b3e2-ee8134ef35f1/ChatGPT_Image_Apr_12__2025__11_32_41_AM.png?t=1744457387"/><div class="image__source"><span class="image__source_text"><p>Token-Based Authentication</p></span></div></div><p class="paragraph" style="text-align:left;">Unlike API keys, tokens are typically short-lived and can contain encoded metadata. They do not require the server to store session data, making them ideal for stateless architectures. Token-based authentication is a common pattern in modern RESTful APIs.</p><div class="codeblock"><pre><code>app.use((req, res, next) =&gt; &#123;
  const token = req.headers[&#39;authorization&#39;]?.split(&#39; &#39;)[1];
  if (token !== &#39;your-token-here&#39;) &#123;
    return res.status(401).send(&#39;Invalid token&#39;);
  &#125;
  next();
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">The code snippet retrieves your token from your request header and checks to make sure it exists. You can do more checks with the token, for example, making sure itis generated by a real user in your application before giving access to the secured resources.</p><h2 class="heading" style="text-align:left;" id="jwt-json-web-tokens">JWT (JSON Web Tokens)</h2><p class="paragraph" style="text-align:left;">JWTs, or JSON Web Tokens, are a specific implementation of token-based authentication that package user identity and claims within the token itself. A JWT consists of three parts: the header, the payload, and the signature. </p><p class="paragraph" style="text-align:left;">The payload contains claims such as user ID, role, and expiration time. The signature is used to verify the integrity of the token.</p><p class="paragraph" style="text-align:left;">JWTs are compact, URL-safe, and can be verified without querying a database, which makes them suitable for scalable, distributed systems. Because they are stateless, JWTs are commonly used in microservices and single-page applications.</p><div class="codeblock"><pre><code>const jwt = require(&#39;jsonwebtoken&#39;);

app.use((req, res, next) =&gt; &#123;
  const token = req.headers[&#39;authorization&#39;]?.split(&#39; &#39;)[1];
  if (!token) return res.status(401).send(&#39;Missing token&#39;);

  try &#123;
    const decoded = jwt.verify(token, process.env.JWT_SECRET);
    req.user = decoded;
    next();
  &#125; catch (err) &#123;
    res.status(403).send(&#39;Invalid or expired token&#39;);
  &#125;
&#125;);</code></pre></div><p class="paragraph" style="text-align:left;">The code snippet above uses the JWT package to verify a token and retrieves the details of the user who created the token. If the token can not be verified, then access is denied.</p><h2 class="heading" style="text-align:left;" id="o-auth-20-authentication">OAuth 2.0 Authentication</h2><p class="paragraph" style="text-align:left;">OAuth 2.0 is a comprehensive framework for delegated authorization. It allows users to authorize third-party applications to access their data without sharing their credentials. OAuth 2.0 defines several flows, including Authorization Code, Implicit, Client Credentials, and Resource Owner Password Credentials, each suited to specific use cases.</p><p class="paragraph" style="text-align:left;">In the OAuth 2.0 architecture, the key roles are the Resource Owner (user), the Client (application), the Authorization Server, and the Resource Server. The client obtains an access token from the Authorization Server and uses it to access resources on the Resource Server.</p><p class="paragraph" style="text-align:left;">OAuth is ideal for scenarios involving third-party applications, such as &quot;Sign in with Google,&quot; where security and delegation are paramount. Implementing OAuth can be complex and typically requires the use of libraries and secure token storage mechanisms.</p><h2 class="heading" style="text-align:left;" id="session-based-authentication">Session-Based Authentication</h2><p class="paragraph" style="text-align:left;">While not common in purely RESTful APIs, session-based authentication remains relevant for traditional web applications. Upon successful login, the server creates a session and returns a session ID to the client, usually stored in a browser cookie. Subsequent requests include the cookie, allowing the server to associate the request with a session.</p><p class="paragraph" style="text-align:left;">Session-based authentication provides a straightforward user experience and integrates well with web frameworks. However, it requires server-side storage of session state, which can hinder horizontal scalability unless a shared store like Redis is used.</p><h2 class="heading" style="text-align:left;" id="comparing-authentication-methods">Comparing Authentication Methods</h2><p class="paragraph" style="text-align:left;">The following diagram illustrates the relationship between different authentication methods, highlighting their security level and use case complexity.</p><div class="image"><img alt="" class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/824874be-ff07-4c84-aa35-92bf4dcde022/ChatGPT_Image_Apr_12__2025__11_21_33_AM.png?t=1744457330"/><div class="image__source"><span class="image__source_text"><p>Comparing Authentication Methods</p></span></div></div><p class="paragraph" style="text-align:left;">Each authentication method offers a different balance between simplicity, security, and scalability. Basic Authentication and API keys are easier to implement but offer lower security. JWT and OAuth 2.0, while more complex, provide advanced features suitable for modern application architectures.</p><h2 class="heading" style="text-align:left;" id="conclusion">Conclusion</h2><p class="paragraph" style="text-align:left;">Selecting the right authentication method is essential in building secure and user-friendly APIs. As systems grow in complexity and user expectations rise, you must balance ease of use, performance, and security. Token-based authentication and JWTs provide scalable, stateless solutions, while OAuth 2.0 addresses advanced authorization requirements.</p><p class="paragraph" style="text-align:left;">Authentication is just one layer of API security. When combined with authorization, encryption, logging, and rate limiting, it contributes to a resilient and secure API ecosystem. As you build and scale your APIs, invest in choosing and implementing authentication strategies that align with your security goals and application needs.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-api-design-authentication-methods" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p><p class="paragraph" style="text-align:left;"></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=f48d8145-9c77-42c5-a284-b0c90ab984d3&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Error Handling in API Design</title>
  <description>In this issue, we&#39;ll explore best practices for API error handling, structure error responses, and implement a robust error-handling system in a RESTful API using Node.js and Express.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/error-handling-in-api-design</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/error-handling-in-api-design</guid>
  <pubDate>Sat, 05 Apr 2025 16:00:00 +0000</pubDate>
  <atom:published>2025-04-05T16:00:00Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here is what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 220 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-reserve-your-spot"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to reserve your spot.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;">Start learning AI in 2025</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_c6ae000c-18f1-4d0f-8687-c675073badbe_e4221c46&bhcl_id=724be8ae-17dc-4908-9568-1846f64efb28_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/f58a9eaf-b0c9-44d2-b0f4-a4507e19576c/Banner_2.png?t=1732571346"/></a></div><p class="paragraph" style="text-align:left;">Everyone talks about AI, but no one has the time to learn it. So, we found the easiest way to learn AI in as little time as possible: <a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_c6ae000c-18f1-4d0f-8687-c675073badbe_e4221c46&bhcl_id=724be8ae-17dc-4908-9568-1846f64efb28_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The Rundown AI.</a></p><p class="paragraph" style="text-align:left;">It&#39;s a free AI newsletter that keeps you up-to-date on the latest AI news, and teaches you how to apply it in just 5 minutes a day.</p><p class="paragraph" style="text-align:left;">Plus, complete the quiz after signing up and they’ll recommend the best AI tools, guides, and courses – tailored to your needs.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_c6ae000c-18f1-4d0f-8687-c675073badbe_e4221c46&bhcl_id=724be8ae-17dc-4908-9568-1846f64efb28_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up to start learning.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In our previous issue on <a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-what-is-hateoas?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">HATEOAS in API Design</a>, we explored HATEOAS as <span style="color:rgb(55, 65, 81);font-size:16px;">a key concept in designing RESTful APIs (Application Programming Interfaces)</span>,<span style="color:rgb(55, 65, 81);font-size:16px;"> which implies that the API delivers data and</span><span style="color:rgb(55, 65, 81);font-family:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";font-size:16px;"> information about available interactions.</span></p><p class="paragraph" style="text-align:left;">In this issue, we&#39;ll explore best practices for API error handling, structure error responses, and implement a robust error-handling system in a RESTful API using <b>Node.js and Express</b>.</p><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">Error handling is a critical aspect of API design that directly impacts an API&#39;s usability, reliability, and stability. When APIs fail to handle errors properly, consumers experience unexpected failures, making debugging and maintenance more challenging. </p><p class="paragraph" style="text-align:left;">A well-structured error-handling mechanism ensures that issues are properly captured, categorized, and communicated to users, allowing them to respond effectively.</p><h2 class="heading" style="text-align:left;" id="principles-of-effective-error-handl">Principles of Effective Error Handling</h2><h3 class="heading" style="text-align:left;" id="use-standard-http-status-codes">Use Standard HTTP Status Codes</h3><p class="paragraph" style="text-align:left;">HTTP status codes provide a universal language for conveying success or failure responses. Some key categories include:</p><ul><li><p class="paragraph" style="text-align:left;"><b>2xx (Success):</b> Indicates a successful request (e.g., <code>200 OK</code>, <code>201 Created</code>).</p></li><li><p class="paragraph" style="text-align:left;"><b>4xx (Client Errors):</b> Indicates issues with the client request (e.g., <code>400 Bad Request</code>, <code>401 Unauthorized</code>, <code>404 Not Found</code>).</p></li><li><p class="paragraph" style="text-align:left;"><b>5xx (Server Errors):</b> Indicates issues with the API server (e.g., <code>500 Internal Server Error</code>, <code>503 Service Unavailable</code>).</p></li></ul><h3 class="heading" style="text-align:left;" id="provide-meaningful-error-messages">Provide Meaningful Error Messages</h3><p class="paragraph" style="text-align:left;">Error messages should be <b>clear, concise, and actionable</b>. Avoid exposing sensitive internal information; provide details that help clients resolve the issue.</p><p class="paragraph" style="text-align:left;"><b>Bad Example:</b></p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &quot;Something went wrong.&quot;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;"><b>Good Example:</b></p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;INVALID_REQUEST&quot;,
    &quot;message&quot;: &quot;The &#39;email&#39; field is required.&quot;,
    &quot;details&quot;: [
      &#123;
        &quot;field&quot;: &quot;email&quot;,
        &quot;issue&quot;: &quot;Missing required field.&quot;
      &#125;
    ]
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="maintain-a-consistent-error-respons">Maintain a Consistent Error Response Format</h3><p class="paragraph" style="text-align:left;">APIs should return errors in a <b>consistent structure</b> to help developers anticipate and handle them easily.</p><p class="paragraph" style="text-align:left;">A standard error response format might include:</p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;RESOURCE_NOT_FOUND&quot;,
    &quot;message&quot;: &quot;The requested resource was not found.&quot;,
    &quot;details&quot;: []
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="log-errors-for-debugging">Log Errors for Debugging</h3><p class="paragraph" style="text-align:left;">Logging errors helps diagnose issues and improve API reliability. To aid troubleshooting, logs should include error details, timestamps, and request context.</p><h3 class="heading" style="text-align:left;" id="avoid-overexposing-internal-errors">Avoid Overexposing Internal Errors</h3><p class="paragraph" style="text-align:left;">APIs should <b>not</b> reveal sensitive information like stack traces, database errors, or internal implementation details to clients. Instead, they should provide generic error messages and log detailed errors internally.</p><h2 class="heading" style="text-align:left;" id="implementing-error-handling-in-node">Implementing Error Handling in Node.js (Express)</h2><p class="paragraph" style="text-align:left;">Let&#39;s implement a structured error-handling system in a <b>Node.js Express API</b>.</p><p id="define-a-custom-error-class" class="paragraph" style="text-align:left;"><b>Define a Custom Error Class</b></p><div class="codeblock"><pre><code>class ApiError extends Error &#123;
  constructor(statusCode, message, details = []) &#123;
    super(message);
    this.statusCode = statusCode;
    this.details = details;
  &#125;
&#125;</code></pre></div><p id="create-a-centralized-error-handling" class="paragraph" style="text-align:left;"><b>Create a Centralized Error Handling Middleware</b></p><div class="codeblock"><pre><code>const errorHandler = (err, req, res, next) =&gt; &#123;
  const statusCode = err.statusCode || 500;
  const response = &#123;
    error: &#123;
      code: err.code || &quot;INTERNAL_SERVER_ERROR&quot;,
      message: err.message || &quot;An unexpected error occurred.&quot;,
      details: err.details || []
    &#125;
  &#125;;
  
  console.error(&quot;API Error:&quot;, response); // Log error details
  res.status(statusCode).json(response);
&#125;;

module.exports = errorHandler;</code></pre></div><p id="use-the-middleware-in-an-express-ap" class="paragraph" style="text-align:left;"><b>Use the Middleware in an Express App</b></p><div class="codeblock"><pre><code>const express = require(&quot;express&quot;);
const app = express();
const errorHandler = require(&quot;./middlewares/errorHandler&quot;);

app.use(express.json());

// Example Route with Error Handling
app.get(&quot;/user/:id&quot;, async (req, res, next) =&gt; &#123;
  try &#123;
    const userId = req.params.id;
    if (!userId) &#123;
      throw new ApiError(400, &quot;User ID is required.&quot;, [&#123; field: &quot;id&quot;, issue: &quot;Missing parameter&quot; &#125;]);
    &#125;
    // Simulate fetching user (Assume user doesn&#39;t exist)
    throw new ApiError(404, &quot;User not found.&quot;);
  &#125; catch (error) &#123;
    next(error);
  &#125;
&#125;);

// Apply the global error handler
app.use(errorHandler);

app.listen(3000, () =&gt; &#123;
  console.log(&quot;Server running on port 3000&quot;);
&#125;);</code></pre></div><h2 class="heading" style="text-align:left;" id="handling-different-error-scenarios">Handling Different Error Scenarios</h2><p class="paragraph" style="text-align:left;">Now, let’s explore some types of errors and a proper way to send the response to your client.</p><h3 class="heading" style="text-align:left;" id="validation-errors"><b>Validation Errors</b></h3><p class="paragraph" style="text-align:left;">If the request payload is invalid, return <code>400 Bad Request</code> with details.</p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;INVALID_REQUEST&quot;,
    &quot;message&quot;: &quot;Username is required.&quot;,
    &quot;details&quot;: [&#123; &quot;field&quot;: &quot;username&quot;, &quot;issue&quot;: &quot;Missing parameter&quot; &#125;]
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="authentication-authorization-errors"><b>Authentication & Authorization Errors</b></h3><p class="paragraph" style="text-align:left;">Unauthorized access attempts should return <code>401 Unauthorized</code> or <code>403 Forbidden</code>.</p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;UNAUTHORIZED&quot;,
    &quot;message&quot;: &quot;Invalid API key. Access denied.&quot;
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="resource-not-found"><b>Resource Not Found</b></h3><p class="paragraph" style="text-align:left;">When a requested resource doesn’t exist, return <code>404 Not Found</code>.</p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;RESOURCE_NOT_FOUND&quot;,
    &quot;message&quot;: &quot;The requested user was not found.&quot;
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="internal-server-errors"><b>Internal Server Errors</b></h3><p class="paragraph" style="text-align:left;">For unexpected server-side issues, return <code>500 Internal Server Error</code> with a generic message.</p><div class="codeblock"><pre><code>&#123;
  &quot;error&quot;: &#123;
    &quot;code&quot;: &quot;INTERNAL_SERVER_ERROR&quot;,
    &quot;message&quot;: &quot;An unexpected error occurred. Please try again later.&quot;
  &#125;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">A well-defined error-handling strategy is essential for building robust and user-friendly APIs. By using standard HTTP status codes, providing meaningful error messages, maintaining a consistent response structure, and implementing centralized error handling in <b>Node.js</b>, you can significantly enhance the API&#39;s reliability and developer experience.</p><p class="paragraph" style="text-align:left;">Following these best practices ensures that your API remains <b>resilient, predictable, and easy to debug</b>, ultimately improving the overall stability of your system.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=error-handling-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=59dafa9a-e886-451e-bec4-bc4432a00bd6&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Idempotency in API Design</title>
  <description>Idempotency is particularly important for handling retries in distributed systems, network failures, and duplicate requests.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/idempotency-in-api-design</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/idempotency-in-api-design</guid>
  <pubDate>Wed, 02 Apr 2025 17:57:10 +0000</pubDate>
  <atom:published>2025-04-02T17:57:10Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 320 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-reserve-your-spot"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to reserve your spot.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;">Looking for unbiased, fact-based news? Join 1440 today.</h3><div class="image"><a class="image__link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_f12870c8-9d86-42aa-b7a4-3bbc7987cc04_1b75ca79&bhcl_id=5990a551-4ca0-44ad-b861-2b76dce42cfc_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/1bcbfe03-863a-4193-a587-c366a30d8a46/TopicBrain-TrustedByOver4Million.jpg?t=1743467156"/></a></div><p class="paragraph" style="text-align:left;">Join over 4 million Americans who start their day with <a class="link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_f12870c8-9d86-42aa-b7a4-3bbc7987cc04_1b75ca79&bhcl_id=5990a551-4ca0-44ad-b861-2b76dce42cfc_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">1440</a> – your daily digest for unbiased, fact-centric news. From politics to sports, we cover it all by analyzing over 100 sources. Our concise, 5-minute read lands in your inbox each morning at no cost. Experience news without the noise; let 1440 help you make up your own mind. Sign up now and invite your friends and family to be part of the informed.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://l.join1440.com/bh?utm_source=beehiiv&utm_medium=cpc&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&utm_content=prospecting_winner_loser&_bhiiv=opp_f12870c8-9d86-42aa-b7a4-3bbc7987cc04_1b75ca79&bhcl_id=5990a551-4ca0-44ad-b861-2b76dce42cfc_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Subscribe to 1440 today.</a></p><h2 class="heading" style="text-align:left;" id="introduction">Introduction</h2><p class="paragraph" style="text-align:left;">In API design, <b>idempotency</b> is a crucial concept that ensures multiple identical requests have the same effect as a single request. This means that regardless of how many times a client sends the same request, the server&#39;s state remains unchanged beyond the first successful execution.</p><p class="paragraph" style="text-align:left;">Idempotency is particularly important for handling retries in <b>distributed systems</b>, <b>network failures</b>, and <b>duplicate requests</b>. It helps improve API <b>fault tolerance</b>, <b>reliability</b>, and <b>consistency</b>, making them more predictable and user-friendly.</p><h2 class="heading" style="text-align:left;" id="why-is-idempotency-important">Why Is Idempotency Important?</h2><ul><li><p class="paragraph" style="text-align:left;"><b>Prevents Duplicate Transactions: </b>Imagine a user initiating a payment request but losing their internet connection mid-process. If the client retries the request, a non-idempotent API could trigger multiple charges. Implementing idempotency ensures that only one transaction is processed.</p></li><li><p class="paragraph" style="text-align:left;"><b>Supports Safe Retries: </b>Network failures, server crashes, and other transient errors are common in distributed systems. Idempotency allows API clients to retry failed operations without worrying about unintended side effects.</p></li><li><p class="paragraph" style="text-align:left;"><b>Enhances API Predictability: </b>Developers working with idempotent APIs can confidently send multiple requests without concerns about inconsistencies in the application state.</p></li></ul><h2 class="heading" style="text-align:left;" id="http-methods-and-idempotency">HTTP Methods and Idempotency</h2><h3 class="heading" style="text-align:left;" id="idempotent-methods"><b>Idempotent Methods:</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>GET</b>: Fetches a resource without modifying it.</p></li><li><p class="paragraph" style="text-align:left;"><b>PUT</b>: Updates or creates a resource while ensuring the state remains consistent across multiple requests.</p></li><li><p class="paragraph" style="text-align:left;"><b>DELETE</b>: Removes a resource but does not change the state beyond the first request.</p></li></ul><h3 class="heading" style="text-align:left;" id="non-idempotent-methods"><b>Non-Idempotent Methods:</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>POST</b> is often used to create new resources, but repeated requests can lead to duplicate entries unless explicitly handled with idempotency keys.</p></li><li><p class="paragraph" style="text-align:left;"><b>PATCH</b>: Partially modifies a resource and can cause inconsistencies if not designed carefully.</p></li></ul><h2 class="heading" style="text-align:left;" id="implementing-idempotency-in-ap-is">Implementing Idempotency in APIs</h2><h3 class="heading" style="text-align:left;" id="using-idempotency-keys">Using Idempotency Keys</h3><p class="paragraph" style="text-align:left;">An <b>idempotency key</b> is a unique identifier sent with a request to ensure that repeated calls do not lead to unintended side effects. The server stores processed requests and their responses, allowing it to return the same response for subsequent identical requests.</p><ul><li><p class="paragraph" style="text-align:left;"><b>Generate an Idempotency Key: </b>Clients should generate a unique idempotency key (e.g., UUID) and send it in the request headers.</p></li><li><p class="paragraph" style="text-align:left;"><b>Store Request Results: </b>On the server side, store the idempotency key along with the processed request’s response.</p></li><li><p class="paragraph" style="text-align:left;"><b>Reuse Previous Responses: </b>If a request with the same idempotency key is received again, return the stored response instead of reprocessing the request.</p></li></ul><h3 class="heading" style="text-align:left;" id="example-implementation-in-nodejs-wi"><b>Example Implementation in Node.js with Redis</b></h3><div class="codeblock"><pre><code>const express = require(&quot;express&quot;);
const redis = require(&quot;redis&quot;);
const &#123; v4: uuidv4 &#125; = require(&quot;uuid&quot;);

const app = express();
app.use(express.json());

const client = redis.createClient();

app.post(&quot;/process-payment&quot;, async (req, res) =&gt; &#123;
    const idempotencyKey = req.headers[&quot;idempotency-key&quot;];
    if (!idempotencyKey) &#123;
        return res.status(400).json(&#123; error: &quot;Idempotency key is required&quot; &#125;);
    &#125;

    client.get(idempotencyKey, (err, data) =&gt; &#123;
        if (data) &#123;
            return res.json(JSON.parse(data)); // Return stored response
        &#125;

        // Simulate payment processing
        const response = &#123; success: true, transactionId: uuidv4() &#125;;
        client.setex(idempotencyKey, 3600, JSON.stringify(response)); // Store response for 1 hour
        res.json(response);
    &#125;);
&#125;);

app.listen(3000, () =&gt; console.log(&quot;Server running on port 3000&quot;));</code></pre></div><h3 class="heading" style="text-align:left;" id="how-it-works"><b>How It Works:</b></h3><ol start="1"><li><p class="paragraph" style="text-align:left;">Clients send an <code>idempotency-key</code> in the request headers.</p></li><li><p class="paragraph" style="text-align:left;">The server checks Redis for an existing response.</p></li><li><p class="paragraph" style="text-align:left;">If found, it returns the stored response without reprocessing the request.</p></li><li><p class="paragraph" style="text-align:left;">If not found, it processes the request, stores the response in Redis, and returns it to the client.</p></li></ol><h2 class="heading" style="text-align:left;" id="best-practices-for-idempotency">Best Practices for Idempotency</h2><ul><li><p class="paragraph" style="text-align:left;"><b>Require Idempotency Keys for Critical Endpoints: </b>Enforce the use of idempotency keys for operations such as payments, user registrations, and order creations.</p></li><li><p class="paragraph" style="text-align:left;"><b>Set an Expiration for Stored Idempotency Keys: </b>To avoid excessive storage consumption, use <b>TTL (Time-To-Live)</b> on stored idempotency keys.</p></li><li><p class="paragraph" style="text-align:left;"><b>Ensure Database-Level Constraints: </b>Use <b>unique constraints</b> (e.g., transaction IDs) to prevent duplicate records in case of idempotency failures.</p></li><li><p class="paragraph" style="text-align:left;"><b>Implement Logging and Monitoring: </b>Track <b>idempotency key usage</b> and <b>failed attempts</b> for debugging and optimizing API performance.</p></li></ul><p class="paragraph" style="text-align:left;">Idempotency is a fundamental concept in <b>robust API design</b>, ensuring <b>safe retries, consistency, and fault tolerance</b>. By using <b>idempotency keys</b>, <b>deduplicating requests</b>, and implementing <b>proper storage mechanisms</b>, APIs can handle repeated requests <b>efficiently and predictably</b>.</p><p class="paragraph" style="text-align:left;">By adopting <b>idempotent API practices</b>, you enhance the <b>reliability, security, and usability</b> of your APIs, creating a better experience for both developers and end-users.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=idempotency-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=30984478-039f-482a-9e77-8191500583de&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Rate Limiting in API Design</title>
  <description>In this issue, we’ll explore the importance of rate limiting, common strategies used in API design, and implementation examples in Node.js using Express and Redis.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/rate-limiting-in-api-design</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/rate-limiting-in-api-design</guid>
  <pubDate>Sat, 29 Mar 2025 19:16:26 +0000</pubDate>
  <atom:published>2025-03-29T19:16:26Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. The first 500 students will be at $54, others at $100 (We have only 320 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-reserve-your-spot"><b><a class="link" href="https://python30.masteringbackend.com/?ref=newsletter&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to reserve your spot.</a></b></h1><hr class="content_break"><p class="paragraph" style="text-align:left;">In our previous issue on <a class="link" href="https://newsletter.masteringbackend.com/p/pagination-in-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Pagination in API Design</a>, we explored the role of pagination in API design, compared different pagination strategies, and provided detailed implementation examples.</p><p class="paragraph" style="text-align:left;">In this issue, we’ll explore the importance of rate limiting, common strategies used in API design, and implementation examples in Node.js using Express and Redis.</p><p class="paragraph" style="text-align:left;">As APIs become the backbone of modern applications, it is crucial to ensure their stability and prevent abuse. One of the most effective ways to achieve this is <b>rate limiting, </b>a strategy that controls the number of API requests a client can make within a given timeframe.</p><p class="paragraph" style="text-align:left;">Rate limiting is key in managing resource allocation, preventing system overload, and ensuring fair access to resources for all consumers.</p><h2 class="heading" style="text-align:left;" id="why-rate-limiting-matters-in-api-de"><b>Why Rate Limiting Matters in API Design</b></h2><p class="paragraph" style="text-align:left;">Without rate limiting, APIs are vulnerable to excessive requests, which can lead to:</p><ul><li><p class="paragraph" style="text-align:left;"><b>System Overload</b> – High traffic can exhaust server resources, causing slow responses or outages.</p></li><li><p class="paragraph" style="text-align:left;"><b>Denial-of-Service (DoS) Attacks:</b> Malicious users or bots can flood the API with requests, disrupting service for legitimate users.</p></li><li><p class="paragraph" style="text-align:left;"><b>Fair Usage Enforcement</b> – Prevents a single client from consuming disproportionate resources.</p></li><li><p class="paragraph" style="text-align:left;"><b>Cost Control</b> – APIs with pay-per-use models must enforce limits to avoid excessive cloud costs.</p></li></ul><p class="paragraph" style="text-align:left;">By enforcing rate limits, APIs maintain performance, security, and equitable access for all users.</p><h2 class="heading" style="text-align:left;" id="common-rate-limiting-strategies"><b>Common Rate Limiting Strategies</b></h2><p class="paragraph" style="text-align:left;">Rate limiting is typically implemented using one of the following techniques:</p><h3 class="heading" style="text-align:left;" id="fixed-window-rate-limiting"><b>Fixed Window Rate Limiting</b></h3><p class="paragraph" style="text-align:left;">This is a simple approach in which requests are counted within a fixed time window (e.g., 100 requests per minute). Once the limit is exceeded, further requests are blocked until the next time window starts.</p><p class="paragraph" style="text-align:left;"><b>Example: </b>A user can make 100 requests per minute. If they exceed this limit at 30 seconds, they must wait until the next minute to make more requests.</p><p class="paragraph" style="text-align:left;">This strategy is good for Simplicity and predictable enforcement.</p><h3 class="heading" style="text-align:left;" id="sliding-window-rate-limiting"><b>Sliding Window Rate Limiting</b></h3><p class="paragraph" style="text-align:left;">Instead of resetting limits at fixed intervals, this approach considers a rolling timeframe. More accurate and smooth enforcement compared to fixed window limiting.</p><p class="paragraph" style="text-align:left;"><b>Example: </b>If a limit of 100 requests per minute is set, requests are checked within the last 60 seconds at any given moment.</p><p class="paragraph" style="text-align:left;">This strategy is good for APIs with dynamic user activity.</p><h3 class="heading" style="text-align:left;" id="token-bucket-algorithm"><b>Token Bucket Algorithm</b></h3><p class="paragraph" style="text-align:left;">Each client is given a <b>bucket</b> with tokens representing API requests. Every request consumes a token; tokens are replenished at a fixed rate. If the bucket is empty, requests are denied until more tokens are added.</p><p class="paragraph" style="text-align:left;"><b>Example: </b>A client gets 10 tokens per second. If they make 50 requests in one second, they must wait for tokens to replenish.</p><p class="paragraph" style="text-align:left;">This rate-limiting strategy is good for APIs that need a burst tolerance while enforcing limits.</p><h3 class="heading" style="text-align:left;" id="leaky-bucket-algorithm"><b>Leaky Bucket Algorithm</b></h3><p class="paragraph" style="text-align:left;">It is similar to the token bucket but enforces a steady request rate. Requests are processed at a fixed rate, and excess requests are queued. This strategy is good for APIs requiring smooth request flow without sudden bursts.</p><h3 class="heading" style="text-align:left;" id="rate-limiting-by-user-or-ip-address"><b>Rate Limiting by User or IP Address</b></h3><p class="paragraph" style="text-align:left;">Limits requests based on <b>user authentication tokens</b> or <b>IP addresses</b>. Ensures that individual clients do not abuse the API. This strategy is good for Multi-user environments where fairness is important.</p><h2 class="heading" style="text-align:left;" id="implementing-rate-limiting-in-nodej"><b>Implementing Rate Limiting in Node.js with Express & Redis</b></h2><p class="paragraph" style="text-align:left;">One of the best ways to implement rate limiting efficiently is by using <b>Redis</b>, a fast in-memory datastore, alongside <b>Express.js</b>.</p><h3 class="heading" style="text-align:left;" id="step-1-install-dependencies"><b>Step 1: Install Dependencies</b></h3><div class="codeblock"><pre><code>npm install express rate-limit ioredis express-rate-limit-redis</code></pre></div><h3 class="heading" style="text-align:left;" id="step-2-set-up-express-and-redis"><b>Step 2: Set Up Express and Redis</b></h3><div class="codeblock"><pre><code>const express = require(&#39;express&#39;);
const rateLimit = require(&#39;express-rate-limit&#39;);
const RedisStore = require(&#39;rate-limit-redis&#39;);
const &#123; createClient &#125; = require(&#39;ioredis&#39;);

const app = express();
const redisClient = createClient(&#123; host: &#39;localhost&#39;, port: 6379 &#125;);

const limiter = rateLimit(&#123;
    store: new RedisStore(&#123;
        sendCommand: (...args) =&gt; redisClient.call(...args),
    &#125;),
    windowMs: 1 * 60 * 1000, // 1 minute
    max: 100, // Limit each IP to 100 requests per minute
    message: &#39;Too many requests, please try again later.&#39;,
&#125;);

app.use(&#39;/api&#39;, limiter);

app.get(&#39;/api/data&#39;, (req, res) =&gt; &#123;
    res.json(&#123; message: &#39;Success! You are within the rate limit.&#39; &#125;);
&#125;);

app.listen(3000, () =&gt; console.log(&#39;Server running on port 3000&#39;));</code></pre></div><h3 class="heading" style="text-align:left;" id="how-this-works"><b>How This Works</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>A rate limit of 100 requests per minute</b> is enforced.</p></li><li><p class="paragraph" style="text-align:left;">If a user exceeds this limit, they receive a <code>429 Too Many Requests</code> response.</p></li><li><p class="paragraph" style="text-align:left;"><b>Redis is used</b> to store request counts for each client, ensuring efficiency and scalability.</p></li></ul><h2 class="heading" style="text-align:left;" id="best-practices-for-rate-limiting"><b>Best Practices for Rate Limiting</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Use Adaptive Rate Limits</b> – Adjust limits based on user behavior (e.g., stricter limits for anonymous users, relaxed limits for authenticated users).</p></li><li><p class="paragraph" style="text-align:left;"><b>Implement API Key-Based Limits</b> – Assign different limits based on API usage tiers (free vs. premium users).</p></li><li><p class="paragraph" style="text-align:left;"><b>Use Headers to Inform Clients</b> – Return headers like <code>X-RateLimit-Limit</code>, <code>X-RateLimit-Remaining</code>, and <code>X-RateLimit-Reset</code> to help clients manage requests.</p></li><li><p class="paragraph" style="text-align:left;"><b>Combine Rate Limiting with Other Security Measures</b> – Use it alongside authentication, logging, and monitoring to enhance security.</p></li><li><p class="paragraph" style="text-align:left;"><b>Monitor and Analyze Requests</b> – Store rate limit logs to detect patterns of abuse and adjust policies dynamically.</p></li></ol><h2 class="heading" style="text-align:left;" id="conclusion"><b>Conclusion</b></h2><p class="paragraph" style="text-align:left;">Rate limiting is essential to API design, ensuring fairness, security, and system stability. By implementing <b>fixed window, sliding window, token bucket, or leaky bucket</b> strategies, APIs can effectively manage load and prevent abuse.</p><p class="paragraph" style="text-align:left;">Using tools like <b>Express and Redis</b>, backend engineers can enforce rate limits efficiently while providing a smooth experience for legitimate users. Thoughtful design and best practices help maintain high availability and performance.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow"><b>MB Video-Based Courses:</b></a> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=rate-limiting-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=20a6787c-c576-4647-b7ce-1bf5b5ab2bd1&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Pagination in API Design</title>
  <description>In this issue, we will explore the role of pagination in API design, compare different pagination strategies, and provide detailed implementation examples. </description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/pagination-in-api-design</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/pagination-in-api-design</guid>
  <pubDate>Tue, 18 Feb 2025 17:47:59 +0000</pubDate>
  <atom:published>2025-02-18T17:47:59Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. First 400 students at $54 others at $100 (We have only 120 slots left.)</b></p><h1 class="heading" style="text-align:left;" id="click-here-to-reserve-your-spot"><b><a class="link" href="https://projects.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to reserve your spot.</a></b></h1><hr class="content_break"><h3 class="heading" style="text-align:left;" id="theres-a-reason-400000-professional">There’s a reason 400,000 professionals read this daily. </h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&utm_source=beehiiv&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&_bhiiv=opp_0c52c635-8f37-40fa-9943-ea8abd7638d9_65769d95&bhcl_id=1a8ced66-551c-40af-882a-5dcb8f0105fd_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/0b0ebefb-2cf6-4b9c-ae4a-8e80d23b01e3/Ad_The_AI_report.png?t=1742251212"/></a></div><p class="paragraph" style="text-align:left;">Join <a class="link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&utm_source=beehiiv&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&_bhiiv=opp_0c52c635-8f37-40fa-9943-ea8abd7638d9_65769d95&bhcl_id=1a8ced66-551c-40af-882a-5dcb8f0105fd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The AI Report</a>, trusted by 400,000+ professionals at Google, Microsoft, and OpenAI. Get daily insights, tools, and strategies to master practical AI skills that drive results.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email={{email}}&utm_source=beehiiv&utm_campaign={{publication_name_param}}_{{publication_alphanumeric_id}}&_bhiiv=opp_0c52c635-8f37-40fa-9943-ea8abd7638d9_65769d95&bhcl_id=1a8ced66-551c-40af-882a-5dcb8f0105fd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up now for free and work smarter, not harder.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In our previous issue on <a class="link" href="https://newsletter.masteringbackend.com/p/building-restful-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Building JSON/RESTful APIs</a>, we explored the principles of designing scalable, maintainable, and efficient APIs using REST and JSON. </p><p class="paragraph" style="text-align:left;">However, as your API scales and begins handling large datasets, it becomes impractical to return all data in a single response. </p><p class="paragraph" style="text-align:left;">This is where <b>pagination</b> comes into play.</p><p class="paragraph" style="text-align:left;">In this issue, we will explore the role of pagination in API design, compare different pagination strategies, and provide detailed implementation examples. </p><p class="paragraph" style="text-align:left;">By the end, you&#39;ll have a solid understanding of how to implement pagination effectively in your JSON/RESTful APIs.</p><h2 class="heading" style="text-align:left;" id="why-pagination-matters-in-api-desig"><b>Why Pagination Matters in API Design</b></h2><p class="paragraph" style="text-align:left;">APIs often need to return large datasets, such as:</p><ul><li><p class="paragraph" style="text-align:left;">A list of users in a system</p></li><li><p class="paragraph" style="text-align:left;">Products in an e-commerce catalog</p></li><li><p class="paragraph" style="text-align:left;">Log entries in a monitoring system</p></li></ul><p class="paragraph" style="text-align:left;">If an API were to return thousands (or millions) of records in a single response, the consequences would be severe:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Slow Performance</b> – Large responses increase response time and slow down both the server and the client.</p></li><li><p class="paragraph" style="text-align:left;"><b>High Memory Consumption</b> – Loading all records into memory at once puts unnecessary strain on server resources.</p></li><li><p class="paragraph" style="text-align:left;"><b>Network Overload</b> – Transferring huge JSON responses can cause bandwidth congestion and increase API latency.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Pagination solves these problems by breaking the dataset into smaller chunks (pages), allowing clients to request only what they need.</b></p><h2 class="heading" style="text-align:left;" id="pagination-strategies">Pagination Strategies</h2><p class="paragraph" style="text-align:left;">There are several ways to implement pagination, each with its trade-offs:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Limit-Offset Pagination</b> (Basic Pagination)</p></li><li><p class="paragraph" style="text-align:left;"><b>Cursor-Based Pagination</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Time-Based Pagination</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Keyset Pagination</b></p></li></ol><p class="paragraph" style="text-align:left;">Let&#39;s break them down in detail.</p><h3 class="heading" style="text-align:left;" id="limit-offset-pagination-traditional">Limit-Offset Pagination (Traditional Approach)</h3><p class="paragraph" style="text-align:left;"><b>How it Works</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Clients specify two query parameters:</p><ul><li><p class="paragraph" style="text-align:left;"><code>limit</code> (number of records per page)</p></li><li><p class="paragraph" style="text-align:left;"><code>offset</code> (starting position of the data)</p></li></ul></li><li><p class="paragraph" style="text-align:left;">The server retrieves records starting from the given <code>offset</code> up to the <code>limit</code>.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Example API Call:</b></p><div class="codeblock"><pre><code>GET /users?limit=10&amp;offset=20</code></pre></div><p class="paragraph" style="text-align:left;"><b>SQL Query Example:</b></p><div class="codeblock"><pre><code>SELECT * FROM users ORDER BY id LIMIT 10 OFFSET 20;</code></pre></div><p class="paragraph" style="text-align:left;"><b>Implementation in Node.js (Express + Prisma ORM)</b></p><div class="codeblock"><pre><code>app.get(&#39;/users&#39;, async (req, res) =&gt; &#123;
    const limit = parseInt(req.query.limit) || 10;
    const offset = parseInt(req.query.offset) || 0;

    const users = await prisma.user.findMany(&#123;
        skip: offset,
        take: limit,
        orderBy: &#123; id: &#39;asc&#39; &#125;,
    &#125;);

    res.json(&#123; users, limit, offset &#125;);
&#125;);</code></pre></div><h4 class="heading" style="text-align:left;" id="pros"><b>Pros:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Simple to implement and understand</p></li><li><p class="paragraph" style="text-align:left;">Easy to integrate with SQL databases</p></li></ul><h4 class="heading" style="text-align:left;" id="cons"><b>Cons:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Performance issues with large datasets (OFFSET grows linearly)</p></li><li><p class="paragraph" style="text-align:left;">Skipping rows is inefficient (especially with big tables)</p></li></ul><h3 class="heading" style="text-align:left;" id="cursor-based-pagination">Cursor-Based Pagination</h3><p class="paragraph" style="text-align:left;">This strategy is great for large datasets and a very efficient pagination strategy for millions and billions of datasets.</p><h4 class="heading" style="text-align:left;" id="how-it-works"><b>How it Works</b>:</h4><ul><li><p class="paragraph" style="text-align:left;">Instead of specifying an offset, the client provides a <b>cursor</b> (a unique identifier for the last seen record).</p></li><li><p class="paragraph" style="text-align:left;">The API retrieves the next <code>N</code> records starting <b>after</b> the cursor.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Example API Call:</b></p><div class="codeblock"><pre><code>GET /users?limit=10&amp;cursor=100</code></pre></div><p class="paragraph" style="text-align:left;"><b>SQL Query Example:</b></p><div class="codeblock"><pre><code>SELECT * FROM users WHERE id &gt; 100 ORDER BY id ASC LIMIT 10;</code></pre></div><p class="paragraph" style="text-align:left;">This query will retrieve all the items where the ID is greater than 100 and will stop at the 10th element because of the <code>LIMIT</code> keyword. Then next iteration will start from 111 like that till it finishes the list.</p><p class="paragraph" style="text-align:left;"><b>Implementation in Node.js (Express + Prisma)</b></p><div class="codeblock"><pre><code>app.get(&#39;/users&#39;, async (req, res) =&gt; &#123;
    const limit = parseInt(req.query.limit) || 10;
    const cursor = req.query.cursor ? parseInt(req.query.cursor) : null;

    const users = await prisma.user.findMany(&#123;
        where: cursor ? &#123; id: &#123; gt: cursor &#125; &#125; : &#123;&#125;,
        take: limit,
        orderBy: &#123; id: &#39;asc&#39; &#125;,
    &#125;);

    // Set next cursor (last item ID)
    const nextCursor = users.length ? users[users.length - 1].id : null;

    res.json(&#123; users, nextCursor &#125;);
&#125;);
</code></pre></div><h4 class="heading" style="text-align:left;" id="pros"><b>Pros:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Efficient for large datasets (avoids expensive OFFSET operations)</p></li><li><p class="paragraph" style="text-align:left;">Fast and scalable</p></li></ul><h4 class="heading" style="text-align:left;" id="cons"><b>Cons:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Requires a unique and indexed sorting field (like <code>id</code>)</p></li><li><p class="paragraph" style="text-align:left;">Cannot jump to arbitrary pages easily</p></li></ul><h2 class="heading" style="text-align:left;" id="time-based-pagination"><b>Time-Based Pagination</b></h2><p class="paragraph" style="text-align:left;">Time-based pagination is mostly used for real-time pagination, and it’s very efficient when used with WebSocket and other real-time applications.</p><p class="paragraph" style="text-align:left;"><b>How it Works</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Instead of an offset, pagination is based on timestamps.</p></li><li><p class="paragraph" style="text-align:left;">Clients fetch records <b>newer or older than a given timestamp</b>.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Example API Call:</b></p><div class="codeblock"><pre><code>GET /logs?limit=10&amp;after=2024-02-17T12:30:00Z</code></pre></div><p class="paragraph" style="text-align:left;"><b>SQL Query Example:</b></p><div class="codeblock"><pre><code>SELECT * FROM logs WHERE created_at &gt; &#39;2024-02-17T12:30:00Z&#39; ORDER BY created_at ASC LIMIT 10;</code></pre></div><p class="paragraph" style="text-align:left;"><b>Implementation in Node.js (Express + Prisma)</b></p><div class="codeblock"><pre><code>app.get(&#39;/logs&#39;, async (req, res) =&gt; &#123;
    const limit = parseInt(req.query.limit) || 10;
    const after = req.query.after ? new Date(req.query.after) : null;

    const logs = await prisma.logs.findMany(&#123;
        where: after ? &#123; createdAt: &#123; gt: after &#125; &#125; : &#123;&#125;,
        take: limit,
        orderBy: &#123; createdAt: &#39;asc&#39; &#125;,
    &#125;);

    const nextAfter = logs.length ? logs[logs.length - 1].createdAt : null;

    res.json(&#123; logs, nextAfter &#125;);
&#125;);
</code></pre></div><h4 class="heading" style="text-align:left;" id="pros"><b>Pros:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Ideal for real-time updates (chat apps, logs, notifications)</p></li><li><p class="paragraph" style="text-align:left;">Efficient indexing with timestamp columns</p></li></ul><h4 class="heading" style="text-align:left;" id="cons"><b>Cons:</b></h4><ul><li><p class="paragraph" style="text-align:left;">Prone to issues with time zone inconsistencies</p></li><li><p class="paragraph" style="text-align:left;">Does not support jumping to specific pages</p></li></ul><h2 class="heading" style="text-align:left;" id="keyset-pagination"><b>Keyset Pagination</b></h2><p class="paragraph" style="text-align:left;">Keyset-based pagination is an alternative cursor-based pagination.</p><p class="paragraph" style="text-align:left;"><b>How it Works</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Uses <b>multiple</b> unique columns (e.g., <code>id</code> + <code>created_at</code>) to determine the next page.</p></li><li><p class="paragraph" style="text-align:left;">It prevents inconsistencies when sorting by fields that are not unique.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Example Query:</b></p><div class="codeblock"><pre><code>SELECT * FROM orders 
WHERE (created_at, id) &gt; (&#39;2024-02-17T12:30:00Z&#39;, 100) 
ORDER BY created_at ASC, id ASC LIMIT 10;</code></pre></div><h4 class="heading" style="text-align:left;" id="pros"><b>Pros:</b></h4><ul><li><p class="paragraph" style="text-align:left;">More stable sorting for non-unique fields</p></li><li><p class="paragraph" style="text-align:left;">Efficient for ordered datasets</p></li></ul><h4 class="heading" style="text-align:left;" id="cons"><b>Cons:</b></h4><ul><li><p class="paragraph" style="text-align:left;">More complex implementation</p></li></ul><h2 class="heading" style="text-align:left;" id="best-practices-for-api-pagination"><b>Best Practices for API Pagination</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Choose the Right Pagination Strategy</b></p><ul><li><p class="paragraph" style="text-align:left;">Use <b>limit-offset</b> for small datasets.</p></li><li><p class="paragraph" style="text-align:left;">Use <b>cursor-based</b> for large datasets.</p></li><li><p class="paragraph" style="text-align:left;">Use <b>time-based</b> for real-time applications.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Return Pagination Metadata</b></p><ul><li><p class="paragraph" style="text-align:left;">Always include pagination metadata (<code>nextCursor</code>, <code>nextPage</code>, <code>totalPages</code>).</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Optimize Database Queries</b></p><ul><li><p class="paragraph" style="text-align:left;">Use <b>indexed fields</b> for filtering (e.g., <code>id</code>, <code>created_at</code>).</p></li><li><p class="paragraph" style="text-align:left;">Avoid <code>OFFSET</code> in large tables when possible.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Consider Client Usability</b></p><ul><li><p class="paragraph" style="text-align:left;">Ensure clients can navigate easily (<code>next</code>, <code>previous</code>, <code>first</code>, <code>last</code> links).</p></li></ul></li></ol><p class="paragraph" style="text-align:left;">Pagination is an essential component of API design, ensuring efficient data retrieval while maintaining performance and scalability. Choosing the right pagination strategy depends on your API&#39;s requirements—<b>limit-offset</b> is simple but inefficient for large datasets, while <b>cursor-based and keyset pagination</b> is ideal for high-performance applications.</p><p class="paragraph" style="text-align:left;">Implementing these best practices, backend engineers can design scalable, performant APIs that provide clients with a seamless experience while optimizing backend resources.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 <b>FaceUp</b><br>✍️<b> Node.js Backend Developer for FaceUp</b><br>📍Remote, Prague, Brno<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/integration-engineer-with-typescript-for-faceup-startup-with-social-impact-K0Jh2F?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 ROIVENUE<br>✍️ <b>Full-stack Software Developer</b><br>📍Remote, Prague<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/full-stack-software-developer-2dmx7Q?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-nHJoS4?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=pagination-in-api-design" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=88f20a99-d457-4e23-ab5e-de41926fb4e0&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Building RESTful APIs</title>
  <description>This issue will explore the fundamentals of building JSON/RESTful APIs, outline their benefits, and provide best practices and code examples to help you design APIs that are both efficient and easy to integrate.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/building-restful-apis</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/building-restful-apis</guid>
  <pubDate>Sat, 08 Feb 2025 15:07:32 +0000</pubDate>
  <atom:published>2025-02-08T15:07:32Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate “Land Your Dream Job” Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. First 400 students at $54 others at $100 (We have only 120 slots left.)</b></p><p class="paragraph" style="text-align:left;"><b>Reply “Challenge” and I will send you a link to reserve your spot.</b></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Check out our sponsor for this episode:</p><h3 class="heading" style="text-align:left;" id="writer-rag-tool-build-productionrea">Writer RAG tool: build production-ready RAG apps in minutes</h3><div class="image"><a class="image__link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_9716dcaf-236c-477a-8cf5-458639b46273_3b00bf9b&bhcl_id=718d16cc-4c9b-481d-a06a-9e153147e9da_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/e2028307-3de3-43f9-b7a5-f2c31418a552/2024-12_Writer_RAG_tool__build_production-ready_RAG_apps_in_minutes_-_16_9_Newsletter.png?t=1734711822"/></a></div><ul><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_9716dcaf-236c-477a-8cf5-458639b46273_3b00bf9b&bhcl_id=718d16cc-4c9b-481d-a06a-9e153147e9da_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Writer RAG Tool</a>: build production-ready RAG apps in minutes with simple API calls.</p></li><li><p class="paragraph" style="text-align:left;">Knowledge Graph integration for intelligent data retrieval and AI-powered interactions.</p></li><li><p class="paragraph" style="text-align:left;">Streamlined full-stack platform eliminates complex setups for scalable, accurate AI workflows.</p></li></ul><p class="paragraph" style="text-align:left;"><a class="link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_9716dcaf-236c-477a-8cf5-458639b46273_3b00bf9b&bhcl_id=718d16cc-4c9b-481d-a06a-9e153147e9da_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Learn more about our production ready RAG tooling here.</a></p><p class="paragraph" style="text-align:left;">In the last newsletter issue, we discussed <a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-how-do-server-sent-events-sse-work?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">How Server-Sent Events (SSE) Work</a> and explained everything you need to know about them. Most importantly, we explored how <b>Server-Sent Events (SSE) </b>works.</p><p class="paragraph" style="text-align:left;">Let’s deep dive into <b>Building a RESTful API</b> today and learn the intricacies of building an API, including <b>Pagination</b>, <b>Rate Limiting</b>, <b>Idempotency</b>, <b>HATEOAS</b>, <b>Error Handling</b>, etc. We will cover these topics in each newsletter issue. But for today, let’s look at how to build a simple RESTful/JSON API using Express.js.</p><h2 class="heading" style="text-align:left;" id="understanding-the-fundamentals">Understanding the Fundamentals</h2><h3 class="heading" style="text-align:left;" id="what-is-rest">What Is REST?</h3><p class="paragraph" style="text-align:left;">REST is an architectural style that defines a set of constraints and principles for building distributed systems. At its core, REST emphasizes:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Statelessness</b>: Each request from a client must contain all the necessary information for the server to process it. The server does not store client context between requests, enabling scalability and reliability.</p></li><li><p class="paragraph" style="text-align:left;"><b>Resource Orientation</b>: Resources (such as users, products, or orders) are identified by unique URLs. Operations on these resources are performed using standard HTTP methods (GET, POST, PUT, DELETE).</p></li><li><p class="paragraph" style="text-align:left;"><b>Uniform Interface</b>: A consistent interface simplifies the interaction between clients and servers, making APIs easier to use and understand.</p></li></ul><h3 class="heading" style="text-align:left;" id="why-json">Why JSON?</h3><p class="paragraph" style="text-align:left;">JSON is a lightweight data interchange format known for its simplicity and readability. Its key attributes include:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Ease of Use</b>: JSON&#39;s key-value pair structure is straightforward and intuitive, making it accessible to both humans and machines.</p></li><li><p class="paragraph" style="text-align:left;"><b>Lightweight</b>: Its minimal syntax reduces payload size, leading to faster data transmission.</p></li><li><p class="paragraph" style="text-align:left;"><b>Language Agnostic</b>: Almost every modern programming language supports JSON, ensuring seamless integration across diverse systems.</p></li></ul><p class="paragraph" style="text-align:left;">By leveraging JSON as the medium for data exchange, RESTful APIs become easier to work with and integrate, helping you to build interconnected systems more efficiently.</p><h2 class="heading" style="text-align:left;" id="key-principles-in-building-ap-is">Key Principles in Building APIs</h2><p class="paragraph" style="text-align:left;">When designing and implementing a JSON/RESTful API, consider the following architectural constraints and design principles:</p><h3 class="heading" style="text-align:left;" id="resource-identification-and-naming-"><b>Resource Identification and Naming Conventions</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>Clear Endpoints</b>: Use meaningful, pluralized nouns to represent collections (e.g., <code>/users</code>, <code>/orders</code>) and singular nouns for individual resources (e.g., <code>/users/123</code>).</p></li><li><p class="paragraph" style="text-align:left;"><b>Consistent URL Structure</b>: Keep endpoint naming uniform and intuitive to facilitate discovery and ease of use.</p></li></ul><h3 class="heading" style="text-align:left;" id="utilizing-standard-http-methods"><b>Utilizing Standard HTTP Methods</b></h3><p class="paragraph" style="text-align:left;">RESTful APIs use standard HTTP methods to perform operations on resources:</p><ul><li><p class="paragraph" style="text-align:left;"><b>GET</b>: Retrieve resource representations.</p></li><li><p class="paragraph" style="text-align:left;"><b>POST</b>: Create a new resource.</p></li><li><p class="paragraph" style="text-align:left;"><b>PUT/PATCH</b>: Update an existing resource.</p></li><li><p class="paragraph" style="text-align:left;"><b>DELETE</b>: Remove a resource.</p></li></ul><p class="paragraph" style="text-align:left;">Using these methods consistently aligns your API with RESTful principles and simplifies client-server interactions.</p><h3 class="heading" style="text-align:left;" id="embracing-statelessness"><b>Embracing Statelessness</b></h3><p class="paragraph" style="text-align:left;">Every request must be self-contained:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Complete Information</b>: Each request should carry all the data needed for processing, such as authentication tokens or query parameters.</p></li><li><p class="paragraph" style="text-align:left;"><b>Scalability</b>: Stateless interactions make it easier to distribute load across multiple servers and handle high traffic volumes.</p></li></ul><h3 class="heading" style="text-align:left;" id="data-representation-and-format"><b>Data Representation and Format</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>JSON as the Data Format</b>: JSON’s widespread acceptance makes it ideal for information interchange. It’s human-readable and easily parsed by client-side applications.</p></li><li><p class="paragraph" style="text-align:left;"><b>Schema and Versioning</b>: Document the structure of your JSON payloads using schemas and maintain versioned endpoints (e.g., <code>/api/v1/users</code>) to manage changes without disrupting existing clients.</p></li></ul><h3 class="heading" style="text-align:left;" id="error-handling-and-status-codes"><b>Error Handling and Status Codes</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>HTTP Status Codes</b>: Use standard HTTP status codes to indicate the outcome of a request:</p><ul><li><p class="paragraph" style="text-align:left;"><code>200 OK</code> for successful requests.</p></li><li><p class="paragraph" style="text-align:left;"><code>201 Created</code> for successful resource creation.</p></li><li><p class="paragraph" style="text-align:left;"><code>400 Bad Request</code> for malformed requests.</p></li><li><p class="paragraph" style="text-align:left;"><code>404 Not Found</code> when resources cannot be found.</p></li><li><p class="paragraph" style="text-align:left;"><code>500 Internal Server Error</code> for unexpected failures.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Structured Error Messages</b>: Return JSON-formatted error messages that provide clear details about what went wrong.</p></li></ul><h2 class="heading" style="text-align:left;" id="practical-example">Practical Example</h2><p class="paragraph" style="text-align:left;">This example will be built with Node.js because it is simple and easy to understand by everyone. For those, who do not write Node.js, you can use ChatGPT to cover the code to any programming language of your choice.</p><p class="paragraph" style="text-align:left;">Below is a simple implementation using <b>Node.js</b> and <b>Express</b> to illustrate how you can build a JSON/RESTful API.</p><h3 class="heading" style="text-align:left;" id="step-1-setting-up-the-environment">Step 1: Setting Up the Environment</h3><p class="paragraph" style="text-align:left;">First, create a new Node.js project and install Express:</p><div class="codeblock"><pre><code>mkdir json-rest-api
cd json-rest-api
npm init -y
npm install express</code></pre></div><h3 class="heading" style="text-align:left;" id="step-2-create-the-api-server">Step 2: Create the API Server</h3><p class="paragraph" style="text-align:left;">Create a file named <code>app.js</code>:</p><div class="codeblock"><pre><code>const express = require(&#39;express&#39;);
const app = express();

// Middleware to parse JSON bodies
app.use(express.json());

// Sample in-memory data store
let users = [
  &#123; id: 1, name: &#39;Alice&#39;, email: &#39;alice@example.com&#39; &#125;,
  &#123; id: 2, name: &#39;Bob&#39;, email: &#39;bob@example.com&#39; &#125;
];

// GET /users - Retrieve all users
app.get(&#39;/users&#39;, (req, res) =&gt; &#123;
  res.status(200).json(users);
&#125;);

// GET /users/:id - Retrieve a user by ID
app.get(&#39;/users/:id&#39;, (req, res) =&gt; &#123;
  const user = users.find(u =&gt; u.id === parseInt(req.params.id, 10));
  if (user) &#123;
    res.status(200).json(user);
  &#125; else &#123;
    res.status(404).json(&#123; error: &#39;User not found&#39; &#125;);
  &#125;
&#125;);

// POST /users - Create a new user
app.post(&#39;/users&#39;, (req, res) =&gt; &#123;
  const newUser = &#123;
    id: Date.now(),
    name: req.body.name,
    email: req.body.email
  &#125;;
  users.push(newUser);
  res.status(201).json(newUser);
&#125;);

// PUT /users/:id - Update an existing user
app.put(&#39;/users/:id&#39;, (req, res) =&gt; &#123;
  const userIndex = users.findIndex(u =&gt; u.id === parseInt(req.params.id, 10));
  if (userIndex !== -1) &#123;
    users[userIndex] = &#123; ...users[userIndex], ...req.body &#125;;
    res.status(200).json(users[userIndex]);
  &#125; else &#123;
    res.status(404).json(&#123; error: &#39;User not found&#39; &#125;);
  &#125;
&#125;);

// DELETE /users/:id - Delete a user
app.delete(&#39;/users/:id&#39;, (req, res) =&gt; &#123;
  const userIndex = users.findIndex(u =&gt; u.id === parseInt(req.params.id, 10));
  if (userIndex !== -1) &#123;
    const deletedUser = users.splice(userIndex, 1);
    res.status(200).json(&#123; message: &#39;User deleted&#39;, user: deletedUser &#125;);
  &#125; else &#123;
    res.status(404).json(&#123; error: &#39;User not found&#39; &#125;);
  &#125;
&#125;);

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () =&gt; console.log(`API running on http://localhost:$&#123;PORT&#125;`));
</code></pre></div><p class="paragraph" style="text-align:left;">This is a simple example of a demo RESTful where we are using an in-memory array storage mechanism instead of a database. Every other action is about manipulating the array to get results and convert them to JSON.</p><h2 class="heading" style="text-align:left;" id="benefits-of-building-jsonres-tful-a">Benefits of Building JSON/RESTful APIs</h2><ul><li><p class="paragraph" style="text-align:left;"><b>Scalability</b>: Stateless interactions allow the API to scale horizontally across multiple servers.</p></li><li><p class="paragraph" style="text-align:left;"><b>Maintainability</b>: Clear separation of concerns and adherence to REST principles makes the API easier to maintain.</p></li><li><p class="paragraph" style="text-align:left;"><b>Integration</b>: Standardized protocols and data formats ensure seamless integration with other systems and services.</p></li><li><p class="paragraph" style="text-align:left;"><b>Performance</b>: Lightweight JSON reduces data overhead, leading to faster communication between client and server.</p></li></ul><p class="paragraph" style="text-align:left;">Building APIs involves more than just sending and receiving data. It’s about adhering to principles that ensure your API is scalable, maintainable, and easily integrated with other systems.</p><p class="paragraph" style="text-align:left;">In the upcoming series, we will explore the following concepts <b>Pagination</b>, <b>Rate Limiting</b>, <b>Idempotency</b>, <b>HATEOAS</b>, and <b>Error Handling</b>, and expand the simple API above into a more robust and enterprise-ready API. Whether you&#39;re developing a simple application or a complex enterprise system, mastering these principles is essential for creating robust and future-proof APIs.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 <b>FaceUp</b><br>✍️<b> Node.js Backend Developer for FaceUp</b><br>📍Remote, Prague, Brno<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/integration-engineer-with-typescript-for-faceup-startup-with-social-impact-K0Jh2F?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 ROIVENUE<br>✍️ <b>Full-stack Software Developer</b><br>📍Remote, Prague<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/full-stack-software-developer-2dmx7Q?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-nHJoS4?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Monzo<br>✍️<b> Backend Engineer</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-Jpo7g7?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=building-restful-apis" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p><p class="paragraph" style="text-align:left;"></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=a8a7fe73-57cd-4f2f-a8db-f1edacc389d3&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How Do Server-Sent Events (SSE) Work</title>
  <description>This issue will explore how SSE works, its advantages over other real-time communication methods, and best practices for designing SSE-powered APIs.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-do-server-sent-events-sse-work</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-do-server-sent-events-sse-work</guid>
  <pubDate>Wed, 05 Feb 2025 16:23:03 +0000</pubDate>
  <atom:published>2025-02-05T16:23:03Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate Land Your Dream Job Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;">It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;">Ship 30+ Python backend projects in 30 days.</p></li><li><p class="paragraph" style="text-align:left;">Instant Access to all 30+ videos</p></li><li><p class="paragraph" style="text-align:left;">Access to data structure and algorithm interview kits.</p></li><li><p class="paragraph" style="text-align:left;">Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</p></li><li><p class="paragraph" style="text-align:left;">Join & learn from a thriving community of helpful students & alumni from top companies.</p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. First 400 students at $54 others at $100 (We have only 94 slots left.)</b></p><p class="paragraph" style="text-align:left;"><b>Reply “Challenge” and I will send you a link to reserve your spot.</b></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Check out our sponsor for this episode:</p><h3 class="heading" style="text-align:left;" id="start-learning-ai-in-2025">Start learning AI in 2025</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_2df4b542-24d9-4b3e-b1c1-76d0b5621f6b_e4221c46&bhcl_id=5d9489ca-c257-4606-8737-1035f1b75dcb_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/f58a9eaf-b0c9-44d2-b0f4-a4507e19576c/Banner_2.png?t=1732571346"/></a></div><p class="paragraph" style="text-align:left;">Everyone talks about AI, but no one has the time to learn it. So, we found the easiest way to learn AI in as little time as possible: <a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_2df4b542-24d9-4b3e-b1c1-76d0b5621f6b_e4221c46&bhcl_id=5d9489ca-c257-4606-8737-1035f1b75dcb_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The Rundown AI.</a></p><p class="paragraph" style="text-align:left;">It&#39;s a free AI newsletter that keeps you up-to-date on the latest AI news, and teaches you how to apply it in just 5 minutes a day.</p><p class="paragraph" style="text-align:left;">Plus, complete the quiz after signing up and they’ll recommend the best AI tools, guides, and courses – tailored to your needs.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_2df4b542-24d9-4b3e-b1c1-76d0b5621f6b_e4221c46&bhcl_id=5d9489ca-c257-4606-8737-1035f1b75dcb_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up to start learning.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In the last newsletter issue, we discussed <a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-how-websockets-works?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">How WebSockets Works</a> and explained everything you need to know about them. Most importantly, we identified two important types of Real-time APIs: <b>WebSockets</b> and <b>Server-Sent Events (SSE)</b>.</p><p class="paragraph" style="text-align:left;">Let’s deep dive into <b>Server-Sent Events (SSE)</b> today and learn the intricacies of SSE, including a simple program that shows how to implement SSE into our projects for real-time application.</p><h2 class="heading" style="text-align:left;" id="overview-of-websockets">Overview of Server-Sent Events (SSE)</h2><p class="paragraph" style="text-align:left;"><b>Server-sent events (SSE)</b> have emerged as a powerful and efficient mechanism for <b>unidirectional data streaming</b>. </p><p class="paragraph" style="text-align:left;">Unlike traditional request-response architectures, where a client continuously polls for updates, SSE enables the server to push data to clients whenever new information becomes available. </p><p class="paragraph" style="text-align:left;">This makes SSE particularly valuable for real-time applications such as <b>live news updates, real-time gaming, stock market feeds, and live-streaming services</b>.</p><p class="paragraph" style="text-align:left;">This issue will explore how SSE works, its advantages over other real-time communication methods, and best practices for designing SSE-powered APIs.</p><h2 class="heading" style="text-align:left;" id="what-are-server-sent-events-sse">What Are Server-Sent Events (SSE)?</h2><p class="paragraph" style="text-align:left;"><b>Server-sent events (SSE)</b> are a real-time API technology built on standard HTTP that allows servers to <b>continuously push updates to clients</b> over a single connection. It uses the <b>EventSource API</b>, which is natively supported by most modern browsers, making it an accessible and efficient solution for real-time communication.</p><p class="paragraph" style="text-align:left;">Unlike <b>WebSockets</b>, which support full-duplex communication (bi-directional data exchange), <b>SSE follows a one-way data flow</b>:</p><ul><li><p class="paragraph" style="text-align:left;">The <b>server</b> continuously sends updates to the <b>client</b>.</p></li><li><p class="paragraph" style="text-align:left;">The <b>client</b> passively listens for updates without needing to request them explicitly.</p></li></ul><p class="paragraph" style="text-align:left;">This <b>push-based architecture</b> reduces network overhead and ensures clients receive real-time updates without repeated polling.</p><p class="paragraph" style="text-align:left;">Now we understand what SSE is and how it differs from WebSockets as we discussed in the previous issue. Next, let’s explore how SSE works.</p><h2 class="heading" style="text-align:left;" id="how-does-sse-work">How Does SSE Work?</h2><p class="paragraph" style="text-align:left;">SSE operates using a <b>long-lived HTTP connection</b> where the server streams events to the client. The interaction follows these key steps:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Client Initiates the Connection: </b>The client opens an HTTP connection to the server using the <code>EventSource</code> API. The server keeps this connection open and sends updates as events occur.</p></li><li><p class="paragraph" style="text-align:left;"><b>Server Pushes Data: </b>Instead of waiting for a new client request, the server automatically pushes data to all connected clients when an update is available.</p></li><li><p class="paragraph" style="text-align:left;"><b>Client Receives Events in Real-Time: </b>The client listens for incoming messages and processes them as they arrive. The connection remains open until the server closes it or the client disconnects.</p></li></ol><h2 class="heading" style="text-align:left;" id="sse-request-and-response-flow">SSE Request and Response Flow</h2><p class="paragraph" style="text-align:left;">Next, let’s look at the request and response flow of a server-sent event and create a simple implementation using Node.js.</p><h4 class="heading" style="text-align:left;" id="client-side-opening-an-sse-connecti">Client-Side: Opening an SSE Connection</h4><p class="paragraph" style="text-align:left;">Using JavaScript’s <code>EventSource</code> API, a client can easily subscribe to an SSE stream:</p><div class="codeblock"><pre><code>const eventSource = new EventSource(&#39;http://example.com/stream&#39;);

eventSource.onmessage = function(event) &#123;
    console.log(&#39;New event received:&#39;, event.data);
&#125;;

eventSource.onerror = function() &#123;
    console.log(&#39;Connection lost, attempting to reconnect...&#39;);
&#125;;</code></pre></div><p class="paragraph" style="text-align:left;">In the code snippet above, you see that we use the JavaScript’s <code>EventSource</code> API to create a new event and listen to incoming messages from the server using the <code>onmessage</code> event.</p><p class="paragraph" style="text-align:left;">Also, we use the <code>onerror</code> event to catch any errors during connection and other errors that might occur during interactions. If the connection is lost, most browsers will <b>automatically retry</b> the connection.</p><h4 class="heading" style="text-align:left;" id="server-side-streaming-events-in-nod">Server-Side: Streaming Events in Node.js</h4><p class="paragraph" style="text-align:left;">Next, let’s look at the server-side implementation of SSE in Node.js:</p><div class="codeblock"><pre><code>const express = require(&#39;express&#39;);
const app = express();

app.get(&#39;/stream&#39;, (req, res) =&gt; &#123;
    res.setHeader(&#39;Content-Type&#39;, &#39;text/event-stream&#39;);
    res.setHeader(&#39;Cache-Control&#39;, &#39;no-cache&#39;);
    res.setHeader(&#39;Connection&#39;, &#39;keep-alive&#39;);

    let counter = 0;

    const interval = setInterval(() =&gt; &#123;
        counter++;
        res.write(`data: &#123;&quot;message&quot;: &quot;Update #$&#123;counter&#125;&quot;, &quot;timestamp&quot;: $&#123;Date.now()&#125;&#125;\n\n`);
    &#125;, 3000);

    req.on(&#39;close&#39;, () =&gt; &#123;
        clearInterval(interval);
    &#125;);
&#125;);

app.listen(3000, () =&gt; console.log(&#39;SSE server running on http://localhost:3000/stream&#39;));
</code></pre></div><p class="paragraph" style="text-align:left;">In the code snippet above, The server sets <code>text/event-stream</code> as the response type to indicate an SSE connection. <code>res.write()</code> is used to continuously push new updates. The connection remains open until the client disconnects or the server closes it.</p><h2 class="heading" style="text-align:left;" id="use-cases-for-sse">Use Cases for SSE</h2><p class="paragraph" style="text-align:left;">SSE is ideal for applications where <b>real-time updates flow in a single direction from server to client</b>:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Live News and Social Media Feeds: </b>Users receive instant updates on breaking news or trending posts.</p></li><li><p class="paragraph" style="text-align:left;"><b>Stock Market and Cryptocurrency Price Updates: </b>Investors see real-time fluctuations without refreshing their dashboards.</p></li><li><p class="paragraph" style="text-align:left;"><b>Live Sports Scores: </b>Fans get live score updates as matches progress.</p></li><li><p class="paragraph" style="text-align:left;"><b>IoT Sensor Data Monitoring: </b>Devices stream sensor data to dashboards in real-time.</p></li><li><p class="paragraph" style="text-align:left;"><b>Customer Support Notifications: </b>Agents receive instant alerts when new customer inquiries arrive.</p></li></ol><h2 class="heading" style="text-align:left;" id="sse-vs-web-sockets-vs-polling">SSE vs. WebSockets vs. Polling</h2><p class="paragraph" style="text-align:left;">Let’s see a clear distinction between SSE, Websockets, and polling.</p><div style="padding:14px 15px 14px;"><table class="bh__table" width="100%" style="border-collapse:collapse;"><tr class="bh__table_row"><th class="bh__table_header" width="25%"><p class="paragraph" style="text-align:left;">Feature</p></th><th class="bh__table_header" width="25%"><p class="paragraph" style="text-align:left;">SSE (Server-Sent Events)</p></th><th class="bh__table_header" width="25%"><p class="paragraph" style="text-align:left;">WebSockets</p></th><th class="bh__table_header" width="25%"><p class="paragraph" style="text-align:left;">Polling</p></th></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Direction</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">One-way (Server → Client)</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Bi-directional</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Client repeatedly requests updates</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Efficiency</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Efficient for server push</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Ideal for real-time interaction</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">High overhead</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Use Case</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Live updates (news, stocks)</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Chat apps, gaming, real-time collaboration</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Basic data sync</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Transport</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Standard HTTP</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">TCP-based WebSocket protocol</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Standard HTTP</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Browser Support</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Native in most browsers</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Requires WebSocket support</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Works everywhere</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;"><b>Auto-Reconnect</b></p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Yes (handled by browser)</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Requires manual handling</p></td><td class="bh__table_cell" width="25%"><p class="paragraph" style="text-align:left;">Requires manual handling</p></td></tr></table></div><ul><li><p class="paragraph" style="text-align:left;"><b>When to use SSE: </b>When <b>only the server</b> needs to send updates (e.g., live feeds, notifications). When <b>simplicity</b> and <b>efficiency</b> are priorities.</p></li><li><p class="paragraph" style="text-align:left;"><b>When to use WebSockets: </b>When the client <b>also needs to send data</b> continuously (e.g., chat applications, online gaming).</p></li><li><p class="paragraph" style="text-align:left;"><b>When to use Polling: </b>When <b>real-time is not critical</b>, but updates are needed periodically (e.g., checking for new emails every 5 minutes).</p></li></ul><h2 class="heading" style="text-align:left;" id="best-practices-for-implementing-sse">Best Practices for Implementing SSE</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Use Proper Headers: </b>Always set <code>Content-Type: text/event-stream</code>, <code>Cache-Control: no-cache</code>, and <code>Connection: keep-alive</code> to ensure smooth streaming.</p></li><li><p class="paragraph" style="text-align:left;"><b>Handle Connection Loss Gracefully: </b>Clients should automatically <b>reconnect</b> when the connection is lost. SSE supports built-in reconnection, but you can use <code>eventSource.onerror</code> to handle failures.</p></li><li><p class="paragraph" style="text-align:left;"><b>Keep Messages Lightweight: </b>Only send necessary data to <b>minimize bandwidth usage</b>. Use <b>JSON serialization</b> for structured messages.</p></li><li><p class="paragraph" style="text-align:left;"><b>Optimize Server Performance: Limit the number of active connections</b> to prevent excessive resource consumption. Consider <b>load balancing</b> for large-scale applications.</p></li><li><p class="paragraph" style="text-align:left;"><b>Secure the Connection: </b>Use <b>HTTPS (wss://)</b> for encrypted communication. Implement <b>authentication tokens</b> to control access.</p></li></ol><p class="paragraph" style="text-align:left;">Server-sent events (SSE) provide a powerful, efficient, and lightweight way for servers to push real-time updates to clients. By leveraging persistent connections, SSE reduces the need for unnecessary polling, leading to better performance and scalability.</p><p class="paragraph" style="text-align:left;">While it may not be suitable for every use case (especially those requiring bi-directional communication), SSE excels in scenarios where the server continuously streams real-time updates—such as live news, stock market tracking, or IoT monitoring.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 <b>FaceUp</b><br>✍️<b> Node.js Backend Developer for FaceUp</b><br>📍Remote, Prague, Brno<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/integration-engineer-with-typescript-for-faceup-startup-with-social-impact-K0Jh2F?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 ROIVENUE<br>✍️ <b>Full-stack Software Developer</b><br>📍Remote, Prague<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/full-stack-software-developer-2dmx7Q?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-nHJoS4?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Monzo<br>✍️<b> Backend Engineer</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-Jpo7g7?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-server-sent-events-sse-work" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=0b70fd40-1bb0-4ca6-8748-23f16a5bd8a8&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How WebSockets Works</title>
  <description>Let’s deep dive into WebSockets today and learn the intricacies of Websockets, including a simple program that shows how to implement Websockets into our projects for real-time application.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-websockets-works</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-websockets-works</guid>
  <pubDate>Thu, 23 Jan 2025 11:22:23 +0000</pubDate>
  <atom:published>2025-01-23T11:22:23Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"><b>The ultimate Land Your Dream Job Challenge is here.</b></p><p class="paragraph" style="text-align:left;">We are launching the ultimate guide to land your dream job in any programming language you choose. We are starting with the Python Programming language.</p><p class="paragraph" style="text-align:left;"><b>Land your dream Python Job in 90 days by shipping 30 Python projects in 30 days by completing our daily tasks.</b></p><p class="paragraph" style="text-align:left;"><b>It’s a cohort-based and project-focused challenge where you will be challenged to build 30 Python projects in 30 days.</b></p><p class="paragraph" style="text-align:left;"><b>Here are what you will get:</b></p><ul><li><p class="paragraph" style="text-align:left;"><b>Ship 30+ Python backend projects in 30 days.</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Instant Access to all 30+ videos</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Access to data structure and algorithm interview kits.</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Access our Complete Backend Job Preparation kits (Resume, Cover letter reviews, mock interviews, and job placements).</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Join & learn from a thriving community of helpful students & alumni from top companies.</b></p></li></ul><p class="paragraph" style="text-align:left;"><b>Limited Access. First 400 students at $54 others at $100 (We have only 113 slots left.)</b></p><p class="paragraph" style="text-align:left;"><b>Reply “Challenge” and I will send you a link to reserve your spot.</b></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Check out our sponsor for this episode:</p><h3 class="heading" style="text-align:left;" id="start-learning-ai-in-2025">Start learning AI in 2025</h3><div class="image"><a class="image__link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_6770dc22-429b-4840-af76-0df39dd10ee7_e4221c46&bhcl_id=df55c3e5-7a05-43fd-aa49-145325964fb7_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/f58a9eaf-b0c9-44d2-b0f4-a4507e19576c/Banner_2.png?t=1732571346"/></a></div><p class="paragraph" style="text-align:left;">Everyone talks about AI, but no one has the time to learn it. So, we found the easiest way to learn AI in as little time as possible: <a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_6770dc22-429b-4840-af76-0df39dd10ee7_e4221c46&bhcl_id=df55c3e5-7a05-43fd-aa49-145325964fb7_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">The Rundown AI.</a></p><p class="paragraph" style="text-align:left;">It&#39;s a free AI newsletter that keeps you up-to-date on the latest AI news, and teaches you how to apply it in just 5 minutes a day.</p><p class="paragraph" style="text-align:left;">Plus, complete the quiz after signing up and they’ll recommend the best AI tools, guides, and courses – tailored to your needs.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://magic.beehiiv.com/v1/4d03390d-2481-4299-b949-ffd8b38b4c38?email={{email}}&utm_campaign={{publication_alphanumeric_id}}&redirect_to=https%3A%2F%2Fsubscribe.therundown.ai%2F%3Fform%3Dopen&redirect_delay=1&_gl=1*1qqix25*_gcl_au*MTYwNDc0Mjg2OC4xNzI5NTMyNjYw*_ga*MTk2YzU4MDctZGFlZi00MjQ3LWIzZDYtYTQ1MTUwMmJiZTQ0*_ga_E6Y4WLQ2EC*MTczMjUxMTg2Ny4yNTkzLjEuMTczMjUxMzM4My42MC4wLjE4NTk3NDE3MTE.&_bhiiv=opp_6770dc22-429b-4840-af76-0df39dd10ee7_e4221c46&bhcl_id=df55c3e5-7a05-43fd-aa49-145325964fb7_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Sign up to start learning.</a></p><hr class="content_break"><p class="paragraph" style="text-align:left;">In the last newsletter issue, we discussed <a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-what-are-real-time-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow"><b>Real-time APIs</b></a> and explained everything you need to know about them. Most importantly, we identified two important types of Real-time APIs: <b>WebSockets</b> and <b>Server-Sent Events (SSE)</b>.</p><p class="paragraph" style="text-align:left;">Let’s deep dive into <b>WebSockets</b> today and learn the intricacies of Websockets, including a simple program that shows how to implement Websockets into our projects for real-time application.</p><h2 class="heading" style="text-align:left;" id="overview-of-websockets">Overview of Websockets</h2><p class="paragraph" style="text-align:left;">Web Sockets provide a long-lived connection between a client and a server over which messages can be transmitted bi-directionally in real time.</p><p class="paragraph" style="text-align:left;">Websockets are very popular because messages can be sent bidirectionally, which means both the server and the client can send and receive messages in real-time.</p><p class="paragraph" style="text-align:left;">WebSockets play a pivotal role in building real-time APIs by providing a faster and more efficient communication channel than traditional HTTP. </p><p class="paragraph" style="text-align:left;">They are widely adopted in scenarios that demand instantaneous data transfer—such as chat applications, live sports updates, and real-time analytics—because they enable seamless, bidirectional communication. </p><p class="paragraph" style="text-align:left;">This shift from conventional HTTP-based API design to a WebSocket-driven approach creates more responsive, dynamic, and efficient APIs capable of handling real-time data.</p><h2 class="heading" style="text-align:left;" id="what-are-web-sockets">What Are WebSockets?</h2><p class="paragraph" style="text-align:left;"><b>WebSockets</b> are a communication protocol designed to support full-duplex (two-way) communication between client and server over a single, long-lived connection.</p><p class="paragraph" style="text-align:left;">Introduced as part of the HTML5 specification, they address the limitations of traditional HTTP by allowing servers to push data to clients without waiting for a client request.</p><p class="paragraph" style="text-align:left;">A simple design right? but very powerful when you think of the numerous complex real-time applications that have been built with it.</p><p class="paragraph" style="text-align:left;">Let’s take a look at some of the key advantages of Websockets:</p><h3 class="heading" style="text-align:left;" id="key-advantages-of-web-sockets">Key Advantages of WebSockets</h3><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Real-time, Two-Way Communication: </b>Data can travel in both directions (client-to-server and server-to-client) simultaneously, making it ideal for real-time applications.</p></li><li><p class="paragraph" style="text-align:left;"><b>Reduced Latency: </b>Once the connection is established, messages flow with minimal overhead, leading to faster data exchange.</p></li><li><p class="paragraph" style="text-align:left;"><b>Efficient Use of Resources: </b>WebSockets eliminates the need for repetitive HTTP handshakes and polling, lowering network usage and server load.</p></li><li><p class="paragraph" style="text-align:left;"><b>Lightweight Messaging: </b>Messages are often sent in simple text or binary format, adding minimal overhead compared to multiple HTTP requests.</p></li></ol><p class="paragraph" style="text-align:left;">Next, let’s look at how WebSockets differ from traditional HTTP, this will help you understand how WebSockets are designed around HTTP protocol.</p><h2 class="heading" style="text-align:left;" id="how-web-sockets-differ-from-http">How WebSockets Differ from HTTP</h2><ul><li><p class="paragraph" style="text-align:left;"><b>Connection Lifecycle</b>: HTTP is request-response based, meaning the client initiates every communication. In contrast, a WebSocket connection remains open, allowing the server to push updates at any time.</p></li><li><p class="paragraph" style="text-align:left;"><b>Protocol Upgrade</b>: WebSockets start as an HTTP handshake, then upgrade the connection via the <code>Upgrade</code> header, switching to the WebSocket protocol <code>ws</code> or <code>wss</code> for secure connections).</p></li><li><p class="paragraph" style="text-align:left;"><b>Message Handling</b>: Instead of sending headers with every request and response as in HTTP, WebSockets exchange lightweight packets (frames), which are efficient for real-time use cases.</p></li></ul><p class="paragraph" style="text-align:left;">Here we highlighted three important concepts which are the Connection Lifecycle which indicates that the connection for a WebSocket remains open for further updates when the traditional HTTP closes and new connections are initiated every time.</p><h2 class="heading" style="text-align:left;" id="establishing-a-web-socket-connectio">Establishing a WebSocket Connection</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Initial HTTP Handshake: </b>The client sends an HTTP request with a <code>Upgrade: websocket</code> header. The server responds with <code>101 Switching Protocols</code> if it supports WebSockets.</p></li><li><p class="paragraph" style="text-align:left;"><b>Upgrading to WebSocket Protocol: </b>After the server accepts, the connection switches from HTTP to the WebSocket protocol. Both ends maintain this upgraded connection until it’s closed by either party.</p></li><li><p class="paragraph" style="text-align:left;"><b>Bi-directional Messaging: </b>With the connection established, the client and server can send messages to each other at any time. There’s no need for further handshakes until the connection is terminated.</p></li></ol><div class="codeblock"><pre><code>const WebSocket = require(&#39;ws&#39;);
const wss = new WebSocket.Server(&#123; port: 8080 &#125;);

wss.on(&#39;connection&#39;, (ws) =&gt; &#123;
  console.log(&#39;New client connected&#39;);

  // Listen for incoming messages
  ws.on(&#39;message&#39;, (message) =&gt; &#123;
    console.log(`Received: $&#123;message&#125;`);
    // Broadcast message to all clients
    wss.clients.forEach((client) =&gt; &#123;
      if (client.readyState === WebSocket.OPEN) &#123;
        client.send(message);
      &#125;
    &#125;);
  &#125;);

  // Handle connection close
  ws.on(&#39;close&#39;, () =&gt; &#123;
    console.log(&#39;Client disconnected&#39;);
  &#125;);
&#125;);</code></pre></div><h2 class="heading" style="text-align:left;" id="use-cases-for-web-sockets">Use Cases for WebSockets</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Chat Applications: </b>Messaging apps like Slack or WhatsApp rely on immediate data flow, allowing users to receive new messages the moment they’re sent.</p></li><li><p class="paragraph" style="text-align:left;"><b>Live Sports Updates: </b>Sports fans want to track scores in near real-time. WebSockets push these updates instantly, enhancing the viewing experience.</p></li><li><p class="paragraph" style="text-align:left;"><b>Financial Trading and Analytics: </b>Stock price fluctuations are time-sensitive. WebSockets provide traders with instantaneous updates, which can be crucial for decision-making.</p></li><li><p class="paragraph" style="text-align:left;"><b>Online Multiplayer Games: </b>Player actions and game states must be synchronized in real-time. WebSockets handle these rapid-fire events efficiently.</p></li></ol><h2 class="heading" style="text-align:left;" id="designing-realtime-ap-is-with-web-s">Designing Real-time APIs with WebSockets</h2><p class="paragraph" style="text-align:left;">Modern applications increasingly adopt WebSockets as a foundation for real-time APIs. This shift from conventional HTTP-based API design to WebSocket-driven architecture helps create APIs that are:</p><ul><li><p class="paragraph" style="text-align:left;"><b>More Responsive</b>: The server can immediately notify clients of new events.</p></li><li><p class="paragraph" style="text-align:left;"><b>Dynamic</b>: Both sides can actively send data, fostering interactive experiences.</p></li><li><p class="paragraph" style="text-align:left;"><b>Efficient</b>: Once established, the connection avoids the overhead of repeated HTTP requests, reducing latency and bandwidth usage.</p></li></ul><p class="paragraph" style="text-align:left;">Because of these advantages, WebSockets have become indispensable for any application that demands seamless, bi-directional communication.</p><h2 class="heading" style="text-align:left;" id="best-practices">Best Practices</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Authentication: </b>Ensure proper authentication before establishing a WebSocket connection. Tokens or cookies are commonly used to verify user identity during the initial handshake.</p></li><li><p class="paragraph" style="text-align:left;"><b>Error Handling: </b>Handle connection errors gracefully, and implement reconnection logic on the client side for scenarios like network interruptions.</p></li><li><p class="paragraph" style="text-align:left;"><b>Scalability: </b>As the number of concurrent connections grows, you’ll need strategies like <b>load balancing</b> and <b>sticky sessions</b> to direct users to the same server instance that maintains their WebSocket connection.</p></li><li><p class="paragraph" style="text-align:left;"><b>Security: </b>Use secure WebSockets (<code>wss://</code>) in production. Always validate incoming data to protect against malicious payloads.</p></li><li><p class="paragraph" style="text-align:left;"><b>Monitoring and Logging: </b>Track metrics like connection count, message throughput, and latency to detect performance issues or bottlenecks in real-time.</p></li></ol><p class="paragraph" style="text-align:left;">WebSockets are at the heart of real-time APIs, offering a faster and more efficient communication channel than traditional HTTP. </p><p class="paragraph" style="text-align:left;">By maintaining a continuous, bi-directional connection, they excel in scenarios demanding instantaneous data transfer—such as chat applications, live sports updates, and real-time analytics. </p><p class="paragraph" style="text-align:left;">This paradigm shift to a WebSocket-based design helps developers build APIs that are both responsive and capable of handling the high demands of today’s data-driven world.</p><p class="paragraph" style="text-align:left;">If you’re building an application where timing and user engagement are paramount, WebSockets may just be the solution you’ve been looking for—empowering you to deliver dynamic, event-driven experiences that feel instantaneous, no matter how many users are online.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 BlueCat<br>✍️<b> Backend Engineer</b><br>📍Remote, Serbia<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-ih0Jgw?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Constructor<br>✍️ <b>Backend Engineer: Experiments Team (Remote)</b><br>📍Remote, <i>Worldwide</i><br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-experiments-team-remote-j9S9l8?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-nHJoS4?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Monzo<br>✍️<b> Backend Engineer</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-Jpo7g7?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-websockets-works" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=cb8b5646-404c-4282-b105-37436d207c79&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: What are Real-time APIs?</title>
  <description>In this article, we’ll explore how Real-time APIs work, common use cases, architectural considerations, and some best practices for effective design.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-what-are-real-time-apis</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-what-are-real-time-apis</guid>
  <pubDate>Sat, 18 Jan 2025 17:02:34 +0000</pubDate>
  <atom:published>2025-01-18T17:02:34Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><p class="paragraph" style="text-align:left;"></p><p class="paragraph" style="text-align:left;">As developers, we are great at building products but selling them becomes a problem because <b>“We hate marketing”?</b></p><p class="paragraph" style="text-align:left;">For me:</p><p class="paragraph" style="text-align:left;">I have been able to crack some of my marketing troubles, especially in the aspect of Copywriting following a book published by the founder of <a class="link" href="https://vec.studio/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Vec Studio</a>.</p><p class="paragraph" style="text-align:left;">If you will someday or now enter into the world of <a class="link" href="https://codepreneurs.dev/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">CodePrenuers</a> then this book is for you.</p><p class="paragraph" style="text-align:left;">It’s 100% free</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://vec.studio/product-led-storytelling-playbook?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to download the book</a></p><hr class="content_break"><h3 class="heading" style="text-align:left;" id="drowning-in-support-tickets-maven-a">Drowning In Support Tickets? Maven AGI is here to help.</h3><div class="image"><a class="image__link" href="https://www.mavenagi.com/demo?utm_campaign=3580835-beehiv_{{publication_alphanumeric_id}}&utm_source=beehiv&_bhiiv=opp_d3f79679-79f1-4c85-b46d-6a8e70db7ca0_f2b733d2&bhcl_id=351fa986-d3f0-41f1-a0d9-d6524ee4ab7c_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/c7513ab2-386e-47d7-849b-d04accd7fb37/hero_image_a.jpeg?t=1733241620"/></a></div><p class="paragraph" style="text-align:left;"><a class="link" href="https://www.mavenagi.com/demo?utm_campaign=3580835-beehiv_{{publication_alphanumeric_id}}&utm_source=beehiv&_bhiiv=opp_d3f79679-79f1-4c85-b46d-6a8e70db7ca0_f2b733d2&bhcl_id=351fa986-d3f0-41f1-a0d9-d6524ee4ab7c_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Maven AGI</a> platform simplifies customer service by unifying systems, improving with every interaction, and automating up to 93% of responses. Seamlessly integrated with 50+ tools like Salesforce, Freshdesk, and Zendesk, <a class="link" href="https://www.mavenagi.com/demo?utm_campaign=3580835-beehiv_{{publication_alphanumeric_id}}&utm_source=beehiv&_bhiiv=opp_d3f79679-79f1-4c85-b46d-6a8e70db7ca0_f2b733d2&bhcl_id=351fa986-d3f0-41f1-a0d9-d6524ee4ab7c_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Maven</a> can deploy AI agents across multiple channels—text, email, web, voice, and apps—within days. Companies like Tripadvisor, ClickUp, and Rho slash response times by 60%, ensuring quicker support and exceptional customer satisfaction. Don’t let support tickets slow you down</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://www.mavenagi.com/demo?utm_campaign=3580835-beehiv_{{publication_alphanumeric_id}}&utm_source=beehiv&_bhiiv=opp_d3f79679-79f1-4c85-b46d-6a8e70db7ca0_f2b733d2&bhcl_id=351fa986-d3f0-41f1-a0d9-d6524ee4ab7c_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Request a free personalized demo today.</a></p><p class="paragraph" style="text-align:left;"></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Modern applications increasingly demand live updates and instantaneous communication. Whether it’s receiving stock market price changes or chatting with friends in a messaging app, <b>Real-time APIs</b> have become a critical part of delivering up-to-the-second information.</p><p class="paragraph" style="text-align:left;">Imagine seeing a live match and there was a goal where Messi scored and your SportyBet app hasn’t updated it with your bet in it. </p><p class="paragraph" style="text-align:left;">How will you feel?</p><p class="paragraph" style="text-align:left;">Now that’s the importance of Real-time APIs and why you need to understand how it works and how to build one yourself as a backend engineer.</p><p class="paragraph" style="text-align:left;">In this article, we’ll explore how Real-time APIs work, common use cases, architectural considerations, and some best practices for effective design.</p><h2 class="heading" style="text-align:left;" id="what-are-realtime-ap-is">What Are Real-time APIs?</h2><p class="paragraph" style="text-align:left;">At a high level, <b>Real-time APIs</b> are interfaces that push data to clients as soon as new information is available. Instead of sending a request and waiting for a response (as is typical in REST-based interactions), Real-time APIs keep the connection open, allowing the server to publish updates instantly.</p><p class="paragraph" style="text-align:left;">There are key characteristics of Real-time APIs and these characteristics give birth to the different types of real-time APIs we will discuss later.</p><ul><li><p class="paragraph" style="text-align:left;"><b>Persistent Connections</b>: The client and server maintain a long-lived connection, often through <b>WebSockets</b>, <b>Server-Sent Events (SSE)</b>, or other protocols that enable continuous communication.</p></li><li><p class="paragraph" style="text-align:left;"><b>Bi-directional or Uni-directional Flows</b>: In some cases (e.g., <b>WebSockets</b>), both client and server can send messages at any time. In others (e.g., <b>SSE</b>), data flows primarily from the server to the client.</p></li><li><p class="paragraph" style="text-align:left;"><b>Event-driven Updates</b>: The server broadcasts changes—such as a new chat message or a price update—as events that subscribed clients can act upon immediately.</p></li></ul><h2 class="heading" style="text-align:left;" id="common-use-cases">Common Use Cases</h2><p class="paragraph" style="text-align:left;">I have already mentioned a few use cases. However, if your project falls under any of the categories listed below. Then you should consider using real-time APIs to build them.</p><ul><li><p class="paragraph" style="text-align:left;"><b>Live Chat and Messaging Apps</b><br>Platforms like WhatsApp, Slack, or Microsoft Teams use Real-time APIs to deliver messages instantly to participants. As soon as a user sends a message, the server propagates it to all connected clients in real-time.</p></li><li><p class="paragraph" style="text-align:left;"><b>Financial Trading Platforms</b><br>Stock trading and cryptocurrency exchanges rely on real-time updates to track price fluctuations or order book changes. The difference of a few milliseconds can be crucial in high-frequency trading environments.</p></li><li><p class="paragraph" style="text-align:left;"><b>Online Multiplayer Games</b><br>Multiplayer games demand constant state synchronization among players. Real-time APIs handle position updates, score changes, and other game-state events to ensure a smooth experience.</p></li><li><p class="paragraph" style="text-align:left;"><b>Collaborative Tools</b><br>Document editing apps (like Google Docs) allow multiple users to edit the same file simultaneously. Real-time APIs power live updates, highlighting where others are editing and showing changes as they happen.</p></li></ul><h2 class="heading" style="text-align:left;" id="how-realtime-ap-is-work">How Real-time APIs Work</h2><h3 class="heading" style="text-align:left;" id="establishing-a-persistent-connectio"><b>Establishing a Persistent Connection</b></h3><ul><li><p class="paragraph" style="text-align:left;"><b>WebSockets</b>: A full-duplex protocol allowing both the client and server to send data at any time. WebSockets begin as an HTTP handshake, then upgrade to a more efficient TCP-based protocol.</p></li><li><p class="paragraph" style="text-align:left;"><b>Server-Sent Events (SSE)</b>: A one-way channel from server to client. The client subscribes to a stream of events, and the server continuously sends updates as text-based messages.</p></li><li><p class="paragraph" style="text-align:left;"><b>Long Polling</b>: Not truly a persistent connection, but an emulation of real-time behavior where the client sends a request that the server holds open until data is available.</p></li></ul><p class="paragraph" style="text-align:left;">We will discuss these types of real-time APIs in complete detail in the upcoming newsletters.</p><h3 class="heading" style="text-align:left;" id="2-data-transfer-in-real-time">2. <b>Data Transfer in Real Time</b></h3><p class="paragraph" style="text-align:left;">Once the connection is established, the server sends updates to the client whenever new data is available. If using a full-duplex protocol (e.g., WebSockets), the client can also send data to the server without initiating a new request each time.</p><h3 class="heading" style="text-align:left;" id="3-maintaining-connection-state">3. <b>Maintaining Connection State</b></h3><p class="paragraph" style="text-align:left;">Real-time APIs need to manage connections, handling scenarios such as:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Connection Loss</b>: Detecting disconnections and re-establishing when the client comes back online.</p></li><li><p class="paragraph" style="text-align:left;"><b>Scaling</b>: Balancing load across multiple servers while keeping messages consistent and ordered.</p></li></ul><h2 class="heading" style="text-align:left;" id="example-of-realtime-chat-with-web-s">Example of Real-time Chat with WebSockets</h2><p class="paragraph" style="text-align:left;">Below is a simplified Node.js/Express server illustrating how a chat application might handle real-time communication using WebSockets:</p><div class="codeblock"><pre><code>const express = require(&#39;express&#39;);
const http = require(&#39;http&#39;);
const WebSocket = require(&#39;ws&#39;);

const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server(&#123; server &#125;);

wss.on(&#39;connection&#39;, (ws) =&gt; &#123;
  console.log(&#39;New client connected&#39;);

  ws.on(&#39;message&#39;, (message) =&gt; &#123;
    console.log(`Received: $&#123;message&#125;`);
    // Broadcast to all clients
    wss.clients.forEach((client) =&gt; &#123;
      if (client.readyState === WebSocket.OPEN) &#123;
        client.send(message);
      &#125;
    &#125;);
  &#125;);

  ws.on(&#39;close&#39;, () =&gt; &#123;
    console.log(&#39;Client disconnected&#39;);
  &#125;);
&#125;);

server.listen(3000, () =&gt; &#123;
  console.log(&#39;Server is listening on port 3000&#39;);
&#125;);
</code></pre></div><p class="paragraph" style="text-align:left;">The code above uses the WebSocket server to create a connection and await the client’s messages after connection.</p><p class="paragraph" style="text-align:left;">Real-time APIs are vital in scenarios where milliseconds matter—chat apps, financial dashboards, gaming, and collaborative platforms. By maintaining open connections and allowing continuous data exchange, they deliver a seamless, interactive user experience. However, designing such APIs requires careful attention to scalability, security, and connection management.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 BlueCat<br>✍️<b> Backend Engineer</b><br>📍Remote, Serbia<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-ih0Jgw?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Constructor<br>✍️ <b>Backend Engineer: Experiments Team (Remote)</b><br>📍Remote, <i>Worldwide</i><br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-experiments-team-remote-j9S9l8?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-nHJoS4?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Monzo<br>✍️<b> Backend Engineer</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-Jpo7g7?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-what-are-real-time-apis" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=d3058ac8-d6a2-4725-87d0-fe6adc351dec&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>Backend Engineers Welcome to 2025</title>
  <description>A complete breakdown of Backend Weekly 2025 plan including all the content, products and courses that will be released.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/78bf7f90-f650-42d5-9a03-104dbde94b5c/BackendWeekly_Design__6_.png" length="41964" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/backend-engineers-welcome-to-2025</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/backend-engineers-welcome-to-2025</guid>
  <pubDate>Tue, 07 Jan 2025 10:25:52 +0000</pubDate>
  <atom:published>2025-01-07T10:25:52Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Hi everyone, </p><p class="paragraph" style="text-align:left;">I want to use this medium to welcome old and new subscribers to this wonderful new year and also to outline the content direction we are taking to help you become a Great Backend Engineer.</p><p class="paragraph" style="text-align:left;">First, thanks to everyone who stuck with us throughout last year and the new subscribers who joined us.</p><p class="paragraph" style="text-align:left;">Below are some of the products, courses, and content we plan to release this year. As a subscriber to this newsletter, you will have the utmost benefits and huge discounts for any product or courses we share here.</p><h2 class="heading" style="text-align:left;" id="content-plan">Content Plan</h2><p class="paragraph" style="text-align:left;">We have already structured all the content that will be sent out this year. Here’s a summary of our content pipeline.</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>January → API Design</b></p></li><li><p class="paragraph" style="text-align:left;"><b>February → Web Security</b></p></li><li><p class="paragraph" style="text-align:left;"><b>March → Software Testing</b></p></li><li><p class="paragraph" style="text-align:left;"><b>April → Software Design Principles</b></p></li><li><p class="paragraph" style="text-align:left;"><b>May → Search Engines</b></p></li><li><p class="paragraph" style="text-align:left;"><b>June → Deployment</b></p></li><li><p class="paragraph" style="text-align:left;"><b>July → Software Caching</b></p></li><li><p class="paragraph" style="text-align:left;"><b>August → GraphQL</b></p></li><li><p class="paragraph" style="text-align:left;"><b>September → Microservices</b></p></li><li><p class="paragraph" style="text-align:left;"><b>October → Building a SaaS</b></p></li><li><p class="paragraph" style="text-align:left;"><b>November → Data Structures and Algorithms</b></p></li><li><p class="paragraph" style="text-align:left;"><b>December → Containerization and </b><b>CI/CD</b></p></li></ol><p class="paragraph" style="text-align:left;"><a class="link" href="https://ordinary-flyaway-88c.notion.site/2025-Newsletter-Plan-1703a6ffedb480b89c37e5f050d38202?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Click here for a detailed outline</a> of each week’s content with the monthly content topic listed above.</p><p class="paragraph" style="text-align:left;">Don’t enjoy all this wealth of knowledge alone this year.</p><h2 class="heading" style="text-align:left;" id="courses">Courses</h2><p class="paragraph" style="text-align:left;">We planned to complete and release 4 major courses with a detailed roadmap for becoming a Great Backend Engineer.</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Become a Java + Spring Backend Engineer:</b></p></li></ol><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">All-in-one Java and Spring course for learning backend engineering with Java. This comprehensive course is designed for Backend Engineers seeking proficiency in Backend Engineering with Java.</span></p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course comes with:</span></p><ul><li><p class="paragraph" style="text-align:left;">10+ in-depth modules</p></li><li><p class="paragraph" style="text-align:left;">50+ in-depth chapters</p></li><li><p class="paragraph" style="text-align:left;">160+ high-quality lessons</p></li><li><p class="paragraph" style="text-align:left;">48+ hours of video training content</p></li></ul><p class="paragraph" style="text-align:left;">The course is organized into 10 in-depth modules:</p><ul><li><p class="paragraph" style="text-align:left;">Java Essentials</p></li><li><p class="paragraph" style="text-align:left;">Advanced Java</p></li><li><p class="paragraph" style="text-align:left;">Building Backend Systems</p></li><li><p class="paragraph" style="text-align:left;">Design Patterns in Java</p></li><li><p class="paragraph" style="text-align:left;">Building REST APIs</p></li><li><p class="paragraph" style="text-align:left;">Testing In Java</p></li><li><p class="paragraph" style="text-align:left;">GraphQL with Java</p></li><li><p class="paragraph" style="text-align:left;">Microservices in Java</p></li><li><p class="paragraph" style="text-align:left;">Introduction to Kubernetes</p></li><li><p class="paragraph" style="text-align:left;">Containerizing and Deploying Java Applications</p></li><li><p class="paragraph" style="text-align:left;">Build Milestone Projects</p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">We’ve released the first module and will be releasing modules every month to give you some time to practice properly.</span></p><div class="button" style="text-align:left;"><a target="_blank" rel="noopener nofollow noreferrer" class="button__link" style="" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025"><span class="button__text" style=""> Pre-order Now at 44% Discount </span></a></div><ol start="2"><li><p class="paragraph" style="text-align:left;"><b>Become a Python Backend Engineer:</b></p></li></ol><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comprehensive course is designed to guide you through the fundamental and advanced concepts of Python programming, progressing to practical skills for building scalable backend systems, implementing logging and caching, creating REST APIs, exploring GraphQL, testing strategies, containerization, deployment, and hands-on project development.</span></p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course comes with:</span></p><ul><li><p class="paragraph" style="text-align:left;">10+ in-depth modules</p></li><li><p class="paragraph" style="text-align:left;">50+ in-depth chapters</p></li><li><p class="paragraph" style="text-align:left;">300+ high-quality lessons</p></li><li><p class="paragraph" style="text-align:left;">48+ hours of video training content</p></li></ul><p class="paragraph" style="text-align:left;">The course is organized into 10 in-depth modules:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Python Essentials</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Advanced Python</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Building Backend Systems</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Logging and Caching</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Building REST APIs</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Testing In Python</b></p></li><li><p class="paragraph" style="text-align:left;"><b>GraphQL with Python</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Databases In Python</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Containerizing and Deploying Python Applications</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Build Milestone Projects</b></p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">I also prepared two bonus mini-projects and bundled them inside. We will build 10+ </span><b>Python</b><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">-based projects to help you solidify your learnings.</span></p><div class="button" style="text-align:left;"><a target="_blank" rel="noopener nofollow noreferrer" class="button__link" style="" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025"><span class="button__text" style=""> Pre-order Now at 44% Discount </span></a></div><ol start="3"><li><p class="paragraph" style="text-align:left;"><b>Become a Node.js Backend Engineer:</b></p></li></ol><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comprehensive course is designed to guide you through the fundamental and advanced concepts of Node.js programming, progressing to practical skills for building scalable backend systems, implementing logging and caching, creating REST APIs, exploring GraphQL, testing strategies, containerization, deployment, and hands-on project development.</span></p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course comes with:</span></p><ul><li><p class="paragraph" style="text-align:left;">10+ in-depth modules</p></li><li><p class="paragraph" style="text-align:left;">50+ in-depth chapters</p></li><li><p class="paragraph" style="text-align:left;">350+ high-quality lessons</p></li><li><p class="paragraph" style="text-align:left;">48+ hours of video training content</p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course is organized into 10 in-depth modules:</span></p><ul><li><p class="paragraph" style="text-align:left;"><b>Node.js Essentials</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Advanced Node.js</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Building Backend Systems</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Logging and Caching</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Building REST APIs</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Testing In Node.js</b></p></li><li><p class="paragraph" style="text-align:left;"><b>GraphQL with Node.js</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Databases In Node.js</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Containerizing and Deploying Node.js Applications</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Build Milestone Projects</b></p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">We’ve released the first module and will be releasing modules every month to give you some time to practice properly.</span></p><div class="button" style="text-align:left;"><a target="_blank" rel="noopener nofollow noreferrer" class="button__link" style="" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025"><span class="button__text" style=""> Pre-order Now at 44% Discount </span></a></div><ol start="4"><li><p class="paragraph" style="text-align:left;"><b>Become a Rust Backend Engineer:</b></p></li></ol><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comprehensive course is designed to equip you with the essential skills to master Rust programming, progressing to advanced concepts, testing strategies, web development, database connectivity, containerization, and deployment of Rust applications.</span></p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course comes with:</span></p><ul><li><p class="paragraph" style="text-align:left;">10+ in-depth modules</p></li><li><p class="paragraph" style="text-align:left;">50+ in-depth chapters</p></li><li><p class="paragraph" style="text-align:left;">350+ high-quality lessons</p></li><li><p class="paragraph" style="text-align:left;">48+ hours of video training content</p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">The course is organized into 10 in-depth modules:</span></p><ul><li><p class="paragraph" style="text-align:left;"><b>Rust Essentials</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Advanced Rust</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Web development with Rust</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Actix-web framework</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Building REST APIs</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Testing In Rust</b></p></li><li><p class="paragraph" style="text-align:left;"><b>GraphQL with Rust</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Databases In Rust</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Containerizing and Deploying Rust Applications</b></p></li><li><p class="paragraph" style="text-align:left;"><b>Build Milestone Projects</b></p></li></ul><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">We’ve released the first module and will be releasing modules every month to give you some time to practice properly.</span></p><div class="button" style="text-align:left;"><a target="_blank" rel="noopener nofollow noreferrer" class="button__link" style="" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025"><span class="button__text" style=""> Pre-order Now at 44% Discount </span></a></div><h2 class="heading" style="text-align:left;" id="projects">Projects</h2><p class="paragraph" style="text-align:left;">Below are some of the cool projects we are launching this year.</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>30RubyProjects: </b>This is a challenge-based course where we challenge you to build 30 Ruby projects and land your dream Ruby Backend Role in 90 days.</p></li><li><p class="paragraph" style="text-align:left;"><b>30RustProjects: </b>This is a challenge-based course where we challenge you to build 30 Ruby projects and land your dream Rust Backend Role in 90 days.</p></li><li><p class="paragraph" style="text-align:left;"><b>30PythonProjects: </b>This is a challenge-based course where we challenge you to build 30 Ruby projects and land your dream Python Backend Role in 90 days.</p></li><li><p class="paragraph" style="text-align:left;"><b>30NodejsProjects: </b>This is a challenge-based course where we challenge you to build 30 Ruby projects and land your dream Node.js Backend Role in 90 days.</p></li><li><p class="paragraph" style="text-align:left;"><b>30JavaProjects: </b>This is a challenge-based course where we challenge you to build 30 Ruby projects and land your dream Node.js Backend Role in 90 days.</p></li></ol><p class="paragraph" style="text-align:left;">Each challenge route will cost <b>$50</b> and we will work together including a community of like-minded folks to land you a backend role in 90 days. Each challenge will include Interview preparation kits, data structure, algorithm kits, and many more.</p><p class="paragraph" style="text-align:left;">If you want to make the payment now, you can get a <b>$30</b> flat fee for any route you take available only this week. Reply <b>“Challenge Accepted”</b> and I will send you a link to join the waitlist.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=backend-engineers-welcome-to-2025" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p><p class="paragraph" style="text-align:left;"></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=92c85798-0bd5-41f3-91d2-139c5bdd4750&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How Do Simple JSON APIs Work?</title>
  <description>We will discuss one API style called Simple JSON APIs, we will look at how Simple JSON APIs work and the different components of Simple JSON APIs.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-do-simple-json-apis-work</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-do-simple-json-apis-work</guid>
  <pubDate>Wed, 04 Dec 2024 16:30:50 +0000</pubDate>
  <atom:published>2024-12-04T16:30:50Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><div class="image"><a class="image__link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_b1709eee-685d-4edf-9fce-45d11cae9e4d_adb2cdd1&bhcl_id=b24c951b-657d-4173-a58a-a4d61ad9f610_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="border-radius:0px 0px 0px 0px;border-style:solid;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/3e057fd6-83e2-47c8-ab26-f646200e3db3/Image_from_Google_512x288.png?t=1731516266"/></a></div><h3 class="heading" style="text-align:left;">Unlock Windsurf Editor, by Codeium.</h3><p class="paragraph" style="text-align:left;">Introducing the <a class="link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_b1709eee-685d-4edf-9fce-45d11cae9e4d_adb2cdd1&bhcl_id=b24c951b-657d-4173-a58a-a4d61ad9f610_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Windsurf Editor</a>, the first agentic IDE. All the features you know and love from Codeium’s extensions plus new capabilities such as Cascade that act as collaborative AI agents, combining the best of copilot and agent systems. This flow state of working with AI creates a step-change in AI capability that results in truly magical moments.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_b1709eee-685d-4edf-9fce-45d11cae9e4d_adb2cdd1&bhcl_id=b24c951b-657d-4173-a58a-a4d61ad9f610_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Download It Free Today</a></p><p class="paragraph" style="text-align:left;">Now, back to the business of today.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;">In my previous series, I explored everything you need to know and learn about</span><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;"><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-building-enterprise-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow"> </a></span><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Designs: Different API </a></b><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Styles</a></b><b>.</b></p><p class="paragraph" style="text-align:left;">Today, we will discuss one API style called Simple JSON APIs, we will look at how Simple JSON APIs work and the different components of Simple JSON APIs.</p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comes from my </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;"> under the </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering/api-and-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Design</a> <span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">section. However, I’m only transferring the knowledge here and breaking it down in this series one topic at a time.</span></p><p class="paragraph" style="text-align:left;"><b>Before we move on If you enjoy this newsletter. Invite your friends and get my books for free.</b></p><h2 class="heading" style="text-align:left;" id="how-does-soap-work">How Do Simple JSON APIs Work?</h2><p class="paragraph" style="text-align:left;"><b>Simple JSON APIs</b> have become a cornerstone of modern web and mobile app development in the digital age of connected applications. </p><p class="paragraph" style="text-align:left;">They provide a lightweight, efficient, and intuitive way to exchange data between a client and a server. JSON (JavaScript Object Notation) plays a central role in this process, thanks to its simplicity and compatibility with various programming languages.</p><h2 class="heading" style="text-align:left;" id="what-is-a-json-api">What is a JSON API?</h2><p class="paragraph" style="text-align:left;">A <b>JSON API</b> is an API that uses <b>JSON as its data format</b> for communication between a client (frontend) and a server (backend). JSON APIs facilitate seamless data exchange by structuring information into key-value pairs.</p><p class="paragraph" style="text-align:left;">With its human-readable and lightweight structure, JSON is ideal for APIs designed to perform CRUD operations (Create, Read, Update, Delete) on data. Its versatility has made it the de facto standard for web APIs in various domains, from e-commerce to social media platforms.</p><h2 class="heading" style="text-align:left;" id="how-do-json-ap-is-work">How Do JSON APIs Work?</h2><p class="paragraph" style="text-align:left;">The workflow of a Simple JSON API can be broken down into three primary steps:</p><h3 class="heading" style="text-align:left;" id="the-client-makes-a-request">The client makes a Request</h3><p class="paragraph" style="text-align:left;">A client application (e.g., a web browser, mobile app, or IoT device) sends an HTTP request to the API server. The request specifies:</p><ul><li><p class="paragraph" style="text-align:left;"><b>HTTP Method</b>: Indicates the type of operation (GET, POST, PUT, DELETE, etc.).</p></li><li><p class="paragraph" style="text-align:left;"><b>Endpoint</b>: The URL of the API resource being accessed.</p></li><li><p class="paragraph" style="text-align:left;"><b>Headers</b>: Metadata, including content type (<code>application/json</code>) and authorization tokens (if required).</p></li><li><p class="paragraph" style="text-align:left;"><b>Payload (Body)</b>: Data sent in the request body (typically for POST or PUT methods).</p></li></ul><h5 class="heading" style="text-align:left;" id="example-request"><b>Example Request</b></h5><p class="paragraph" style="text-align:left;">Here’s an HTTP POST request to create a new user:</p><div class="codeblock"><pre><code>POST /api/users HTTP/1.1  
Host: example.com  
Content-Type: application/json  

&#123;  
  &quot;name&quot;: &quot;John Doe&quot;,  
  &quot;email&quot;: &quot;john.doe@example.com&quot;,  
  &quot;password&quot;: &quot;securePassword123&quot;  
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="the-server-processes-the-request">The server Processes the Request</h3><p class="paragraph" style="text-align:left;">The server processes the request in several steps:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Routing</b>: The server determines the endpoint and matches it with the correct handler.</p></li><li><p class="paragraph" style="text-align:left;"><b>Validation</b>: It validates the request data to adhere to the API&#39;s rules.</p></li><li><p class="paragraph" style="text-align:left;"><b>Database Interaction</b>: The server interacts with the database (if needed) to perform the requested operation.</p></li><li><p class="paragraph" style="text-align:left;"><b>Response Creation</b>: After processing, the server sends back a response in JSON format.</p></li></ul><p class="paragraph" style="text-align:left;">Example Backend Code (Node.js)</p><div class="codeblock"><pre><code>const express = require(&#39;express&#39;);
const app = express();

app.use(express.json());

// Endpoint to create a new user
app.post(&#39;/api/users&#39;, (req, res) =&gt; &#123;
  const &#123; name, email, password &#125; = req.body;

  // Simulate saving user to a database
  const newUser = &#123; id: 1, name, email &#125;;

  res.status(201).json(&#123;
    message: &#39;User created successfully&#39;,
    data: newUser,
  &#125;);
&#125;);

app.listen(3000, () =&gt; &#123;
  console.log(&#39;Server running on http://localhost:3000&#39;);
&#125;);</code></pre></div><h3 class="heading" style="text-align:left;" id="client-receives-a-response">Client Receives a Response</h3><p class="paragraph" style="text-align:left;">The server sends a response back to the client. The response contains:</p><ul><li><p class="paragraph" style="text-align:left;"><b>HTTP Status Code</b>: Indicates the outcome (e.g., <code>200 OK</code>, <code>201 Created</code>, <code>400 Bad Request</code>).</p></li><li><p class="paragraph" style="text-align:left;"><b>Headers</b>: Metadata such as <code>Content-Type: application/json</code>.</p></li><li><p class="paragraph" style="text-align:left;"><b>Body</b>: A JSON payload with the result of the operation.</p></li></ul><h5 class="heading" style="text-align:left;" id="example-response"><b>Example Response:</b></h5><div class="codeblock"><pre><code>&#123;
  &quot;message&quot;: &quot;User created successfully&quot;,
  &quot;data&quot;: &#123;
    &quot;id&quot;: 1,
    &quot;name&quot;: &quot;John Doe&quot;,
    &quot;email&quot;: &quot;john.doe@example.com&quot;
  &#125;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">The client processes this response and updates the UI or performs further actions as needed.</p><h3 class="heading" style="text-align:left;" id="why-are-json-ap-is-so-popular">Why Are JSON APIs So Popular?</h3><ul><li><p class="paragraph" style="text-align:left;"><b>Lightweight and Fast</b>: JSON’s compact structure reduces payload size, making APIs faster and more efficient.</p></li><li><p class="paragraph" style="text-align:left;"><b>Human-Readable</b>: JSON’s syntax is easy to read, write, and debug.</p></li><li><p class="paragraph" style="text-align:left;"><b>Cross-Language Support</b>: Virtually all programming languages support JSON parsing.</p></li><li><p class="paragraph" style="text-align:left;"><b>Flexibility</b>: JSON APIs are versatile and can represent complex data structures like arrays and nested objects.</p></li><li><p class="paragraph" style="text-align:left;"><b>Widespread Adoption</b>: JSON APIs are supported by modern tools, frameworks, and libraries, making them a go-to choice for developers.</p></li></ul><h2 class="heading" style="text-align:left;" id="design-principles-for-simple-json-a">Design Principles for Simple JSON APIs</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Use Clear and Intuitive Endpoints: </b>Design endpoints that clearly describe the resource they represent.</p></li></ol><ul><li><p class="paragraph" style="text-align:left;"><code>GET /api/users</code> – Fetch all users.</p></li><li><p class="paragraph" style="text-align:left;"><code>GET /api/users/&#123;id&#125;</code> – Fetch a specific user.</p></li></ul><ol start="2"><li><p class="paragraph" style="text-align:left;"><b>Consistent Use of HTTP Methods: </b>Adopt standard HTTP methods for different operations:</p></li></ol><ul><li><p class="paragraph" style="text-align:left;"><code>GET</code>: Retrieve data.</p></li><li><p class="paragraph" style="text-align:left;"><code>POST</code>: Create new resources.</p></li><li><p class="paragraph" style="text-align:left;"><code>PUT</code>/<code>PATCH</code>: Update resources.</p></li><li><p class="paragraph" style="text-align:left;"><code>DELETE</code>: Remove resources.</p></li></ul><ol start="3"><li><p class="paragraph" style="text-align:left;"><b>Return Meaningful HTTP Status Codes: </b>Always return appropriate status codes to reflect the result of the operation.</p></li></ol><ul><li><p class="paragraph" style="text-align:left;"><code>200 OK</code> – Request succeeded.</p></li><li><p class="paragraph" style="text-align:left;"><code>201 Created</code> – Resource successfully created.</p></li><li><p class="paragraph" style="text-align:left;"><code>400 Bad Request</code> – Invalid request data.</p></li><li><p class="paragraph" style="text-align:left;"><code>401 Unauthorized</code> – Missing or invalid authentication.</p></li></ul><ol start="4"><li><p class="paragraph" style="text-align:left;"><b>Structure JSON Responses Properly: </b>Organize JSON responses to include metadata, data, and error information.</p></li></ol><div class="codeblock"><pre><code>&#123;
  &quot;success&quot;: true,
  &quot;data&quot;: &#123;
    &quot;id&quot;: 1,
    &quot;name&quot;: &quot;John Doe&quot;,
    &quot;email&quot;: &quot;john.doe@example.com&quot;
  &#125;,
  &quot;error&quot;: null
&#125;</code></pre></div><ol start="5"><li><p class="paragraph" style="text-align:left;"><b>Secure the API: </b>Use authentication (e.g., Token-Based Auth, OAuth) and HTTPS to protect data in transit.</p></li></ol><h2 class="heading" style="text-align:left;" id="advantages-of-simple-json-ap-is">Advantages of Simple JSON APIs</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Ease of Integration</b>: Simple JSON APIs are straightforward to implement and consume.</p></li><li><p class="paragraph" style="text-align:left;"><b>Scalability</b>: They work seamlessly across devices, platforms, and networks.</p></li><li><p class="paragraph" style="text-align:left;"><b>Developer-Friendly</b>: Widely supported by tools and frameworks, JSON APIs speed up development.</p></li><li><p class="paragraph" style="text-align:left;"><b>Reduced Overhead</b>: Smaller payloads mean better performance, especially for mobile applications.</p></li></ol><p class="paragraph" style="text-align:left;">Simple JSON APIs are the backbone of modern application development. By leveraging JSON&#39;s lightweight, readable structure, these APIs enable seamless communication between clients and servers. Their simplicity, combined with robust design principles, makes them a preferred choice for developers building scalable and efficient web and mobile applications.</p><p class="paragraph" style="text-align:left;">Whether you are developing a small app or a large enterprise system, mastering Simple JSON APIs is a key step toward creating robust and user-friendly solutions.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:<br><br><b>Get a 50% discount on any of these courses. Reach out to me (Reply to this mail)</b></p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-do-simple-json-apis-work" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=f8ea8b8e-af6b-4b9a-bebc-3500f868318b&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How Does SOAP Work?</title>
  <description>We will discuss one API style called SOAP, we will look at how SOAP works and the different components of SOAP.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-does-soap-work</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-does-soap-work</guid>
  <pubDate>Sat, 30 Nov 2024 17:26:42 +0000</pubDate>
  <atom:published>2024-11-30T17:26:42Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><h3 class="heading" style="text-align:left;" id="try-the-internets-easiest-file-api">Try the internet’s easiest File API</h3><div class="image"><a class="image__link" href="https://pinata.cloud/?utm_source=beehiiv&utm_medium=paid&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_598dee90-a7cf-4356-84af-1ebe6a19d9ab_1bd08b6e&bhcl_id=30b92460-db2c-4377-82f8-dcc95b4ea4fd_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/185282a6-568d-46d8-b233-0fef7e1a8790/1.png?t=1727795873"/></a></div><p class="paragraph" style="text-align:left;">Tired of spending hours setting up file management systems? <a class="link" href="https://pinata.cloud/?utm_source=beehiiv&utm_medium=paid&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_598dee90-a7cf-4356-84af-1ebe6a19d9ab_1bd08b6e&bhcl_id=30b92460-db2c-4377-82f8-dcc95b4ea4fd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Pinata’s</a> File API makes it effortless. With simple integration, you can add file uploads and retrieval to your app in minutes, allowing you to focus on building features instead of wasting time on unnecessary configurations. Our API provides fast, secure, and scalable file management without the hassle of maintaining infrastructure.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://pinata.cloud/?utm_source=beehiiv&utm_medium=paid&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_598dee90-a7cf-4356-84af-1ebe6a19d9ab_1bd08b6e&bhcl_id=30b92460-db2c-4377-82f8-dcc95b4ea4fd_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Try it now!</a></p><p class="paragraph" style="text-align:left;">Now, back to the business of today.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;">In my previous series, I explored everything you need to know and learn about</span><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;"><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-building-enterprise-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow"> </a></span><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">API and API Designs: Different API </a></b><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Styles</a></b><b>.</b></p><p class="paragraph" style="text-align:left;">Today, we will discuss one API style called SOAP, we will look at how SOAP works and the different components of SOAP.</p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comes from my </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;"> under the </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering/api-and-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">API and API Design</a> <span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">section. However, I’m only transferring the knowledge here and breaking it down in this series one topic at a time.</span></p><h2 class="heading" style="text-align:left;" id="how-does-soap-work">How Does SOAP Work?</h2><p class="paragraph" style="text-align:left;">In the world of API communication, <b>Simple Object Access Protocol (SOAP)</b> stands as one of the most robust and structured methods for exchanging data. </p><p class="paragraph" style="text-align:left;">Introduced in the late 1990s, SOAP remains a powerful choice for enterprises requiring reliable and standardized communication between systems. </p><p class="paragraph" style="text-align:left;">But how does SOAP work, and what makes it suitable for specific use cases? </p><p class="paragraph" style="text-align:left;">Let&#39;s explore:</p><h2 class="heading" style="text-align:left;" id="what-is-soap">What is SOAP?</h2><p class="paragraph" style="text-align:left;">SOAP is a <b>protocol for exchanging structured information</b> to implement web services. Unlike REST, an architectural style, SOAP is a strict protocol defined by standards from the <b>World Wide Web Consortium (W3C)</b>. </p><p class="paragraph" style="text-align:left;">SOAP messages are XML-based, ensuring platform-agnostic communication between applications.</p><p class="paragraph" style="text-align:left;">SOAP is ideal for scenarios requiring <b>high security</b>, <b>ACID-compliant transactions</b>, or <b>complex operations</b>, such as banking or telecommunication services.</p><h2 class="heading" style="text-align:left;" id="key-components-of-soap">Key Components of SOAP</h2><p class="paragraph" style="text-align:left;">SOAP works through a combination of the following components:</p><h3 class="heading" style="text-align:left;" id="1-soap-envelope">1. <b>SOAP Envelope</b></h3><p class="paragraph" style="text-align:left;">The SOAP Envelope is the container for the message. It defines the start and end of the message and includes metadata about the message.</p><h3 class="heading" style="text-align:left;" id="2-soap-header">2. <b>SOAP Header</b></h3><p class="paragraph" style="text-align:left;">The Header is optional and contains metadata such as authentication credentials, transaction ID, or routing information.</p><h3 class="heading" style="text-align:left;" id="3-soap-body">3. <b>SOAP Body</b></h3><p class="paragraph" style="text-align:left;">The Body holds the actual message or the data to be processed. This is where requests and responses are encapsulated.</p><h3 class="heading" style="text-align:left;" id="4-wsdl-web-services-description-lan">4. <b>WSDL (Web Services Description Language)</b></h3><p class="paragraph" style="text-align:left;">WSDL is an XML-based contract that describes the operations a SOAP service offers, including the parameters, return types, and endpoints.</p><h2 class="heading" style="text-align:left;" id="how-soap-works">How SOAP Works</h2><h3 class="heading" style="text-align:left;" id="step-1-client-sends-a-request">Step 1: Client Sends a Request</h3><p class="paragraph" style="text-align:left;">The client generates a SOAP request message, encapsulated in an XML document. This message includes the operation to be performed and the necessary parameters</p><div class="codeblock"><pre><code>&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soap:Header&gt;
    &lt;auth&gt;
      &lt;username&gt;exampleUser&lt;/username&gt;
      &lt;password&gt;securePassword&lt;/password&gt;
    &lt;/auth&gt;
  &lt;/soap:Header&gt;
  &lt;soap:Body&gt;
    &lt;GetUserDetails xmlns=&quot;http://example.com/&quot;&gt;
      &lt;UserID&gt;123&lt;/UserID&gt;
    &lt;/GetUserDetails&gt;
  &lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;</code></pre></div><h3 class="heading" style="text-align:left;" id="step-2-transmission-via-http">Step 2: Transmission via HTTP</h3><p class="paragraph" style="text-align:left;">The SOAP request is sent over HTTP or HTTPS to the server. Although HTTP is the most common transport protocol, SOAP can also work with SMTP, FTP, or other protocols.</p><h3 class="heading" style="text-align:left;" id="step-3-server-processes-the-request">Step 3: Server Processes the Request</h3><p class="paragraph" style="text-align:left;">On the server side:</p><ul><li><p class="paragraph" style="text-align:left;">The SOAP message is parsed to understand the requested operation.</p></li><li><p class="paragraph" style="text-align:left;">The server performs the requested action using the provided parameters (e.g., fetching user data from a database).</p></li><li><p class="paragraph" style="text-align:left;">The server generates a SOAP response.</p></li></ul><h3 class="heading" style="text-align:left;" id="step-4-server-sends-a-response">Step 4: Server Sends a Response</h3><p class="paragraph" style="text-align:left;">The response is sent back to the client in the form of another SOAP message.</p><p class="paragraph" style="text-align:left;">Example SOAP Response:</p><div class="codeblock"><pre><code>&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soap:Body&gt;
    &lt;GetUserDetailsResponse xmlns=&quot;http://example.com/&quot;&gt;
      &lt;User&gt;
        &lt;UserID&gt;123&lt;/UserID&gt;
        &lt;Name&gt;John Doe&lt;/Name&gt;
        &lt;Email&gt;john.doe@example.com&lt;/Email&gt;
      &lt;/User&gt;
    &lt;/GetUserDetailsResponse&gt;
  &lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;</code></pre></div><p class="paragraph" style="text-align:left;">The client then parses the response and processes the returned data.</p><h2 class="heading" style="text-align:left;" id="advantages-of-soap">Advantages of SOAP</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Platform Independence</b>: SOAP is language and platform-agnostic, thanks to its reliance on XML.</p></li><li><p class="paragraph" style="text-align:left;"><b>Standardized Protocol</b>: It follows strict standards, making it highly interoperable.</p></li><li><p class="paragraph" style="text-align:left;"><b>Security</b>: SOAP supports WS-Security for encryption and authentication, making it ideal for secure transactions.</p></li><li><p class="paragraph" style="text-align:left;"><b>Built-In Error Handling</b>: SOAP messages include fault elements to describe errors in a structured manner.</p></li><li><p class="paragraph" style="text-align:left;"><b>Extensibility</b>: The header can carry additional metadata for custom functionality.</p></li></ol><h2 class="heading" style="text-align:left;" id="disadvantages-of-soap">Disadvantages of SOAP</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Verbosity</b>: XML messages are larger compared to JSON, leading to higher overhead.</p></li><li><p class="paragraph" style="text-align:left;"><b>Complexity</b>: SOAP’s rigid standards and XML syntax can be cumbersome to work with.</p></li><li><p class="paragraph" style="text-align:left;"><b>Performance</b>: The verbosity and processing requirements of XML make SOAP slower than lightweight protocols like REST.</p></li></ol><h1 class="heading" style="text-align:left;" id="how-does-soap-work">How Does SOAP Work?</h1><p class="paragraph" style="text-align:left;">In the world of API communication, <b>Simple Object Access Protocol (SOAP)</b> stands as one of the most robust and structured methods for exchanging data. Introduced in the late 1990s, SOAP remains a powerful choice for enterprises requiring reliable and standardized communication between systems. But how does SOAP work, and what makes it suitable for specific use cases? Let&#39;s explore.</p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="what-is-soap">What is SOAP?</h2><p class="paragraph" style="text-align:left;">SOAP is a <b>protocol for exchanging structured information</b> to implement web services. Unlike REST, an architectural style, SOAP is a strict protocol defined by standards from the <b>World Wide Web Consortium (W3C)</b>. SOAP messages are XML-based, ensuring platform-agnostic communication between applications.</p><p class="paragraph" style="text-align:left;">SOAP is ideal for scenarios requiring <b>high security</b>, <b>ACID-compliant transactions</b>, or <b>complex operations</b>, such as banking or telecommunication services.</p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="key-components-of-soap">Key Components of SOAP</h2><p class="paragraph" style="text-align:left;">SOAP works through a combination of the following components:</p><h3 class="heading" style="text-align:left;" id="1-soap-envelope">1. <b>SOAP Envelope</b></h3><p class="paragraph" style="text-align:left;">The SOAP Envelope is the container for the message. It defines the start and end of the message and includes metadata about the message.</p><h3 class="heading" style="text-align:left;" id="2-soap-header">2. <b>SOAP Header</b></h3><p class="paragraph" style="text-align:left;">The Header is optional and contains metadata such as authentication credentials, transaction ID, or routing information.</p><h3 class="heading" style="text-align:left;" id="3-soap-body">3. <b>SOAP Body</b></h3><p class="paragraph" style="text-align:left;">The Body holds the actual message or the data to be processed. This is where requests and responses are encapsulated.</p><h3 class="heading" style="text-align:left;" id="4-wsdl-web-services-description-lan">4. <b>WSDL (Web Services Description Language)</b></h3><p class="paragraph" style="text-align:left;">WSDL is an XML-based contract describing the SOAP service&#39;s operations, including the parameters, return types, and endpoints.</p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="how-soap-works">How SOAP Works</h2><h3 class="heading" style="text-align:left;" id="step-1-client-sends-a-request">Step 1: Client Sends a Request</h3><p class="paragraph" style="text-align:left;">The client generates a SOAP request message, encapsulated in an XML document. This message includes the operation to be performed and the necessary parameters.</p><p class="paragraph" style="text-align:left;">Example SOAP Request:</p><div class="codeblock"><pre><code>&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soap:Header&gt;
    &lt;auth&gt;
      &lt;username&gt;exampleUser&lt;/username&gt;
      &lt;password&gt;securePassword&lt;/password&gt;
    &lt;/auth&gt;
  &lt;/soap:Header&gt;
  &lt;soap:Body&gt;
    &lt;GetUserDetails xmlns=&quot;http://example.com/&quot;&gt;
      &lt;UserID&gt;123&lt;/UserID&gt;
    &lt;/GetUserDetails&gt;
  &lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;</code></pre></div><hr class="content_break"><h3 class="heading" style="text-align:left;" id="step-2-transmission-via-http">Step 2: Transmission via HTTP</h3><p class="paragraph" style="text-align:left;">The SOAP request is sent over HTTP or HTTPS to the server. Although HTTP is the most common transport protocol, SOAP can also work with SMTP, FTP, or other protocols.</p><hr class="content_break"><h3 class="heading" style="text-align:left;" id="step-3-server-processes-the-request">Step 3: Server Processes the Request</h3><p class="paragraph" style="text-align:left;">On the server side:</p><ul><li><p class="paragraph" style="text-align:left;">The SOAP message is parsed to understand the requested operation.</p></li><li><p class="paragraph" style="text-align:left;">The server performs the requested action using the provided parameters (e.g., fetching user data from a database).</p></li><li><p class="paragraph" style="text-align:left;">The server generates a SOAP response.</p></li></ul><hr class="content_break"><h3 class="heading" style="text-align:left;" id="step-4-server-sends-a-response">Step 4: Server Sends a Response</h3><p class="paragraph" style="text-align:left;">The response is sent back to the client in the form of another SOAP message.</p><p class="paragraph" style="text-align:left;">Example SOAP Response:</p><div class="codeblock"><pre><code>&lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soap:Body&gt;
    &lt;GetUserDetailsResponse xmlns=&quot;http://example.com/&quot;&gt;
      &lt;User&gt;
        &lt;UserID&gt;123&lt;/UserID&gt;
        &lt;Name&gt;John Doe&lt;/Name&gt;
        &lt;Email&gt;john.doe@example.com&lt;/Email&gt;
      &lt;/User&gt;
    &lt;/GetUserDetailsResponse&gt;
  &lt;/soap:Body&gt;
&lt;/soap:Envelope&gt;
</code></pre></div><p class="paragraph" style="text-align:left;">The client then parses the response and processes the returned data.</p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="advantages-of-soap">Advantages of SOAP</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Platform Independence</b>: SOAP is language and platform-agnostic, thanks to its reliance on XML.</p></li><li><p class="paragraph" style="text-align:left;"><b>Standardized Protocol</b>: It follows strict standards, making it highly interoperable.</p></li><li><p class="paragraph" style="text-align:left;"><b>Security</b>: SOAP supports WS-Security for encryption and authentication, making it ideal for secure transactions.</p></li><li><p class="paragraph" style="text-align:left;"><b>Built-In Error Handling</b>: SOAP messages include fault elements to describe errors in a structured manner.</p></li><li><p class="paragraph" style="text-align:left;"><b>Extensibility</b>: The header can carry additional metadata for custom functionality.</p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="disadvantages-of-soap">Disadvantages of SOAP</h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Verbosity</b>: XML messages are larger compared to JSON, leading to higher overhead.</p></li><li><p class="paragraph" style="text-align:left;"><b>Complexity</b>: SOAP’s rigid standards and XML syntax can be cumbersome to work with.</p></li><li><p class="paragraph" style="text-align:left;"><b>Performance</b>: The verbosity and processing requirements of XML make SOAP slower than lightweight protocols like REST.</p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="use-cases-for-soap">Use Cases for SOAP</h2><p class="paragraph" style="text-align:left;">Despite the rise of REST and GraphQL, SOAP remains a critical protocol in industries where <b>security, reliability, and standardization</b> are paramount.</p><h3 class="heading" style="text-align:left;" id="common-scenarios">Common Scenarios:</h3><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Financial Transactions</b>: Banking APIs often use SOAP for secure, ACID-compliant operations.</p></li><li><p class="paragraph" style="text-align:left;"><b>Telecommunications</b>: SOAP is used for provisioning services and managing billing systems.</p></li><li><p class="paragraph" style="text-align:left;"><b>Government Services</b>: Standardization and security make SOAP a preferred choice for inter-governmental systems.</p></li><li><p class="paragraph" style="text-align:left;"><b>Enterprise Applications</b>: ERP and CRM systems often integrate using SOAP.</p></li></ol><h2 class="heading" style="text-align:left;" id="comparison-soap-vs-rest">Comparison: SOAP vs. REST</h2><div style="padding:14px 15px 14px;"><table class="bh__table" width="100%" style="border-collapse:collapse;"><tr class="bh__table_row"><th class="bh__table_header" width="33%"><p class="paragraph" style="text-align:left;">Feature</p></th><th class="bh__table_header" width="33%"><p class="paragraph" style="text-align:left;">SOAP</p></th><th class="bh__table_header" width="33%"><p class="paragraph" style="text-align:left;">REST</p></th></tr><tr class="bh__table_row"><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Protocol Type</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Strict Protocol</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Architectural Style</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Data Format</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">XML</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">JSON, XML, etc.</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Security</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">WS-Security</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">OAuth, Token-Based</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Statefulness</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Stateful or Stateless</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Stateless</p></td></tr><tr class="bh__table_row"><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Ease of Use</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Complex</p></td><td class="bh__table_cell" width="33%"><p class="paragraph" style="text-align:left;">Simple</p></td></tr></table></div><p class="paragraph" style="text-align:left;"></p><p class="paragraph" style="text-align:left;">SOAP continues to serve as a backbone for enterprise-level APIs where <b>security</b>, <b>reliability</b>, and <b>interoperability</b> are non-negotiable. Its strict protocol, built-in error handling, and extensibility make it a preferred choice in high-stakes industries, despite its verbosity and complexity.</p><p class="paragraph" style="text-align:left;">While modern API developers often lean toward REST or GraphQL for flexibility, understanding how SOAP works equips engineers to maintain and integrate with legacy systems or secure, regulated environments.</p><p class="paragraph" style="text-align:left;">By mastering SOAP, developers can bridge the gap between legacy systems and modern applications, ensuring robust communication and data integrity across platforms.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-does-soap-work" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=e97d7630-44b8-436d-8c40-831c055ee1ab&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How gRPC APIs Work?</title>
  <description>We will discuss one API style called gRPC, we will look at how gRPC works and the different components of gRPC.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-grpc-apis-work</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-grpc-apis-work</guid>
  <pubDate>Thu, 28 Nov 2024 15:56:50 +0000</pubDate>
  <atom:published>2024-11-28T15:56:50Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><h3 class="heading" style="text-align:left;" id="writer-rag-tool-build-productionrea">Writer RAG tool: build production-ready RAG apps in minutes</h3><div class="image"><a class="image__link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_6ad8797b-cf66-49e0-b3ee-04640de74c8d_3b00bf9b&bhcl_id=139824ef-7ecc-40ec-83f0-b227bc541d1f_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/084a99d5-aef3-4091-8df9-944aa56a75cd/2024-12_Writer_RAG_tool__build_production-ready_RAG_apps_in_minutes_-_16_9_Newsletter.png?t=1734711598"/></a></div><p class="paragraph" style="text-align:left;">RAG in just a few lines of code? We’ve launched a predefined RAG tool on our developer platform, making it easy to bring your data into a Knowledge Graph and interact with it with AI. With a single API call, writer LLMs will intelligently call the RAG tool to chat with your data.</p><p class="paragraph" style="text-align:left;">Integrated into <a class="link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_6ad8797b-cf66-49e0-b3ee-04640de74c8d_3b00bf9b&bhcl_id=139824ef-7ecc-40ec-83f0-b227bc541d1f_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Writer’s full-stack platform</a>, it eliminates the need for complex vendor RAG setups, making it quick to build scalable, highly accurate AI workflows just by passing a graph ID of your data as a parameter to your RAG tool.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://writer.com/engineering/rag-tool/?utm_source=beehiiv&utm_medium=newsletter&utm_campaign=rag-tool_{{publication_alphanumeric_id}}_{{publication_name_param}}&_bhiiv=opp_6ad8797b-cf66-49e0-b3ee-04640de74c8d_3b00bf9b&bhcl_id=139824ef-7ecc-40ec-83f0-b227bc541d1f_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Learn more about our production ready RAG tooling here.</a></p><p class="paragraph" style="text-align:left;">Now, back to the business of today.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;">In my previous series, I explored everything you need to know and learn about</span><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;"><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-building-enterprise-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow"> </a></span><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Designs: Different API </a></b><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Styles</a></b><b>.</b></p><p class="paragraph" style="text-align:left;">Today, we will discuss one API style called gRPC, we will look at how gRPC works and the different components of gRPC.</p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comes from my </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;"> under the </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering/api-and-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Design</a> <span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">section. However, I’m only transferring the knowledge here and breaking it down in this series one topic at a time.</span></p><h2 class="heading" style="text-align:left;" id="how-does-graph-ql-work">How Does gRPC Work?</h2><p class="paragraph" style="text-align:left;">In the realm of modern distributed systems, <b>gRPC</b> has emerged as a high-performance framework for building efficient and scalable APIs. Developed by Google, gRPC (short for <b>gRPC Remote Procedure Call</b>) builds on HTTP/2 and Protocol Buffers (Protobuf) to deliver low-latency communication, strong typing, and cross-platform interoperability.</p><p class="paragraph" style="text-align:left;">We’ll dive into the inner workings of gRPC, explaining its components, benefits, and real-world applications.</p><h2 class="heading" style="text-align:left;" id="what-is-g-rpc">What Is gRPC?</h2><p class="paragraph" style="text-align:left;">gRPC is an open-source, high-performance framework that enables seamless communication between client and server applications. Unlike REST, which revolves around resources and HTTP verbs, gRPC uses a <b>Remote Procedure Call (RPC)</b> model, allowing clients to invoke methods on a remote server as if they were local function calls.</p><p class="paragraph" style="text-align:left;">Key features of gRPC include:</p><ul><li><p class="paragraph" style="text-align:left;"><b>Efficient Serialization</b> with Protocol Buffers.</p></li><li><p class="paragraph" style="text-align:left;"><b>Full-Duplex Streaming</b> using HTTP/2.</p></li><li><p class="paragraph" style="text-align:left;"><b>Multi-language Support</b>, enabling polyglot microservices.</p></li><li><p class="paragraph" style="text-align:left;"><b>Bidirectional Communication</b>, making it ideal for real-time applications.</p></li></ul><h2 class="heading" style="text-align:left;" id="how-does-g-rpc-work">How Does gRPC Work?</h2><p class="paragraph" style="text-align:left;">To understand how gRPC works, let’s break it down into its core components and processes:</p><h3 class="heading" style="text-align:left;" id="install-required-packages">Install Required Packages</h3><p class="paragraph" style="text-align:left;">Before we start, install the necessary dependencies:</p><div class="codeblock"><pre><code>npm init -y
npm install @grpc/grpc-js @grpc/proto-loader</code></pre></div><h3 class="heading" style="text-align:left;" id="defining-the-service"><b>Defining the Service</b></h3><p class="paragraph" style="text-align:left;">At the heart of gRPC is the service definition, written in <b>Protocol Buffers (Protobuf)</b>. Protobuf is a language-neutral and platform-independent mechanism for serializing structured data, enabling high-speed communication. The service definition specifies:</p><ul><li><p class="paragraph" style="text-align:left;">The <b>methods</b> available.</p></li><li><p class="paragraph" style="text-align:left;">The <b>request</b> and <b>response</b> data types.</p></li></ul><p class="paragraph" style="text-align:left;">Here’s an example of a Protobuf definition for a simple user service:</p><div class="codeblock"><pre><code>syntax = &quot;proto3&quot;;

service UserService &#123;
  // Unary RPC
  rpc GetUser (UserRequest) returns (UserResponse);

  // Server-streaming RPC
  rpc ListUsers (EmptyRequest) returns (stream UserResponse);
&#125;

message UserRequest &#123;
  int32 id = 1;
&#125;

message UserResponse &#123;
  int32 id = 1;
  string name = 2;
  string email = 3;
&#125;

message EmptyRequest &#123;&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="implement-the-g-rpc-server">Implement the gRPC Server</h3><p class="paragraph" style="text-align:left;">Create a file named <code>server.js</code>:</p><div class="codeblock"><pre><code>const grpc = require(&#39;@grpc/grpc-js&#39;);
const protoLoader = require(&#39;@grpc/proto-loader&#39;);
const PROTO_PATH = &#39;./user.proto&#39;;

// Load the Protobuf file
const packageDefinition = protoLoader.loadSync(PROTO_PATH, &#123;
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
&#125;);

const userProto = grpc.loadPackageDefinition(packageDefinition).UserService;

// Sample user data
const users = &#123;
  1: &#123; id: 1, name: &#39;Alice&#39;, email: &#39;alice@example.com&#39; &#125;,
  2: &#123; id: 2, name: &#39;Bob&#39;, email: &#39;bob@example.com&#39; &#125;,
&#125;;

// Implement the GetUser RPC
function getUser(call, callback) &#123;
  const user = users[call.request.id];
  if (user) &#123;
    callback(null, user);
  &#125; else &#123;
    callback(&#123;
      code: grpc.status.NOT_FOUND,
      details: &#39;User not found&#39;,
    &#125;);
  &#125;
&#125;

// Implement the ListUsers RPC
function listUsers(call) &#123;
  Object.values(users).forEach((user) =&gt; call.write(user));
  call.end();
&#125;

// Start the gRPC server
function main() &#123;
  const server = new grpc.Server();
  server.addService(userProto.service, &#123; GetUser: getUser, ListUsers: listUsers &#125;);
  server.bindAsync(&#39;0.0.0.0:50051&#39;, grpc.ServerCredentials.createInsecure(), () =&gt; &#123;
    console.log(&#39;Server running at http://0.0.0.0:50051&#39;);
    server.start();
  &#125;);
&#125;

main();</code></pre></div><h3 class="heading" style="text-align:left;" id="implement-the-g-rpc-client">Implement the gRPC Client</h3><p class="paragraph" style="text-align:left;">Create a file named <code>client.js</code>:</p><div class="codeblock"><pre><code>const grpc = require(&#39;@grpc/grpc-js&#39;);
const protoLoader = require(&#39;@grpc/proto-loader&#39;);
const PROTO_PATH = &#39;./user.proto&#39;;

// Load the Protobuf file
const packageDefinition = protoLoader.loadSync(PROTO_PATH, &#123;
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
&#125;);
const userProto = grpc.loadPackageDefinition(packageDefinition).UserService;

function main() &#123;
  const client = new userProto(&#39;localhost:50051&#39;, grpc.credentials.createInsecure());

  // Unary RPC: GetUser
  client.GetUser(&#123; id: 1 &#125;, (error, response) =&gt; &#123;
    if (!error) &#123;
      console.log(&#39;User:&#39;, response);
    &#125; else &#123;
      console.error(&#39;Error:&#39;, error.message);
    &#125;
  &#125;);

  // Server-streaming RPC: ListUsers
  const call = client.ListUsers(&#123;&#125;);
  call.on(&#39;data&#39;, (user) =&gt; &#123;
    console.log(&#39;User:&#39;, user);
  &#125;);
  call.on(&#39;end&#39;, () =&gt; &#123;
    console.log(&#39;Finished receiving user list.&#39;);
  &#125;);
&#125;

main();
</code></pre></div><h3 class="heading" style="text-align:left;" id="explanation-of-the-code">Explanation of the Code</h3><p class="paragraph" style="text-align:left;">Here I will try to explain the code above here.</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Server</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Implements the <code>GetUser</code> method for retrieving a single user by ID.</p></li><li><p class="paragraph" style="text-align:left;">Implements the <code>ListUsers</code> method for streaming all users.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Client</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Uses the <code>GetUser</code> method to fetch a single user.</p></li><li><p class="paragraph" style="text-align:left;">Uses the <code>ListUsers</code> method to stream multiple users.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>Protocol Buffers</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Defines the service and message structure in a compact and efficient format.</p></li><li><p class="paragraph" style="text-align:left;">Automatically generates bindings for the server and client.</p></li></ul></li><li><p class="paragraph" style="text-align:left;"><b>HTTP/2</b>:</p><ul><li><p class="paragraph" style="text-align:left;">Enables efficient communication between the client and server.</p></li></ul></li></ol><h4 class="heading" style="text-align:left;" id="key-benefits-of-g-rpc">Key Benefits of gRPC</h4><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>High Performance: </b>Protobuf serialization and HTTP/2 reduce payload size and latency, making gRPC faster than REST.</p></li><li><p class="paragraph" style="text-align:left;"><b>Strong Typing: </b>Protobuf enforces strict typing, reducing runtime errors and improving data validation.</p></li><li><p class="paragraph" style="text-align:left;"><b>Cross-Language Interoperability: </b>gRPC supports multiple languages, enabling seamless integration across diverse systems.</p></li><li><p class="paragraph" style="text-align:left;"><b>Streaming Capabilities: </b>Full-duplex streaming makes gRPC ideal for real-time applications.</p></li><li><p class="paragraph" style="text-align:left;"><b>Code Generation: </b>Automatic generation of client and server code accelerates development.</p></li></ol><h4 class="heading" style="text-align:left;" id="real-world-applications-of-g-rpc">Real-World Applications of gRPC</h4><ul><li><p class="paragraph" style="text-align:left;"><b>Microservices Communication: </b>gRPC excels in internal communication between microservices, where performance and efficiency are critical.</p></li><li><p class="paragraph" style="text-align:left;"><b>Mobile and IoT Applications: </b>gRPC’s compact payloads and HTTP/2 support make it ideal for devices with limited bandwidth.</p></li><li><p class="paragraph" style="text-align:left;"><b>Real-Time Systems: </b>Use cases like live chat, video streaming, and financial trading benefit from gRPC’s streaming capabilities.</p></li></ul><p class="paragraph" style="text-align:left;">gRPC revolutionizes how applications communicate by combining the power of Protocol Buffers, HTTP/2, and a robust RPC model. Its ability to handle diverse communication patterns, deliver high performance, and integrate across languages makes it a top choice for modern API design.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-grpc-apis-work" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=6df9afa1-b9c7-4633-9454-13806dab8afa&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

      <item>
  <title>API and API Design: How GraphQL APIs Work?</title>
  <description>We will discuss one API style called GraphQL, we will look at how GraphQL works and the different components of GraphQL.</description>
      <enclosure url="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/2c01d261-f9af-471b-b5bf-cbc8e1613d55/BackendWeekly_Design__5_.png" length="50489" type="image/png"/>
  <link>https://newsletter.masteringbackend.com/p/api-and-api-design-how-graphql-apis-work</link>
  <guid isPermaLink="true">https://newsletter.masteringbackend.com/p/api-and-api-design-how-graphql-apis-work</guid>
  <pubDate>Tue, 26 Nov 2024 16:14:07 +0000</pubDate>
  <atom:published>2024-11-26T16:14:07Z</atom:published>
    <dc:creator>Solomom Eseme</dc:creator>
    <category><![CDATA[Api Design]]></category>
  <content:encoded><![CDATA[
    <div class='beehiiv'><style>
  .bh__table, .bh__table_header, .bh__table_cell { border: 1px solid #C0C0C0; }
  .bh__table_cell { padding: 5px; background-color: #FFFFFF; }
  .bh__table_cell p { color: #2D2D2D; font-family: 'Helvetica',Arial,sans-serif !important; overflow-wrap: break-word; }
  .bh__table_header { padding: 5px; background-color:#F1F1F1; }
  .bh__table_header p { color: #2A2A2A; font-family:'Trebuchet MS','Lucida Grande',Tahoma,sans-serif !important; overflow-wrap: break-word; }
</style><div class='beehiiv__body'><p class="paragraph" style="text-align:left;">Hello “👋</p><p class="paragraph" style="text-align:left;"><i>Welcome to another week, another opportunity to become a Great Backend Engineer.</i></p><p class="paragraph" style="text-align:left;"><i>Today’s issue is brought to you by </i><span style="text-decoration:underline;"><a class="link" href="https://masteringbackend.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Masteringbackend</a></span><i><b> → A great resource for backend engineers. We offer next-level backend engineering training and exclusive resources.</b></i></p><hr class="content_break"><p class="paragraph" style="text-align:left;">Before we get started, I have a few announcements:</p><p class="paragraph" style="text-align:left;">I have a special gift for you: You will love this one.</p><h3 class="heading" style="text-align:left;" id="unlock-windsurf-editor-by-codeium">Unlock Windsurf Editor, by Codeium.</h3><div class="image"><a class="image__link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_636dc1b0-3c86-4aad-be37-e827b0355af7_adb2cdd1&bhcl_id=af53fe03-432f-44de-8c8c-38da5fe7c9bf_{{subscriber_id}}_{{email_address_id}}" rel="noopener" target="_blank"><img class="image__image" style="" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/3e057fd6-83e2-47c8-ab26-f646200e3db3/Image_from_Google_512x288.png?t=1731516266"/></a></div><p class="paragraph" style="text-align:left;">Introducing the <a class="link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_636dc1b0-3c86-4aad-be37-e827b0355af7_adb2cdd1&bhcl_id=af53fe03-432f-44de-8c8c-38da5fe7c9bf_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Windsurf Editor</a>, the first agentic IDE. All the features you know and love from Codeium’s extensions plus new capabilities such as Cascade that act as collaborative AI agents, combining the best of copilot and agent systems. This flow state of working with AI creates a step-change in AI capability that results in truly magical moments.</p><p class="paragraph" style="text-align:left;"><a class="link" href="https://wind.surf/beehiiv?utm_source=beehiiv&utm_campaign={{publication_alphanumeric_id}}&_bhiiv=opp_636dc1b0-3c86-4aad-be37-e827b0355af7_adb2cdd1&bhcl_id=af53fe03-432f-44de-8c8c-38da5fe7c9bf_{{subscriber_id}}_{{email_address_id}}" target="_blank" rel="noopener noreferrer nofollow">Download It Free Today</a></p><p class="paragraph" style="text-align:left;">Now, back to the business of today.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;">In my previous series, I explored everything you need to know and learn about</span><span style="color:rgb(34, 34, 34);font-family:Helvetica, Arial, sans-serif;font-size:16px;"><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-building-enterprise-apis?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow"> </a></span><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Designs: Different API </a></b><b><a class="link" href="https://newsletter.masteringbackend.com/p/api-and-api-design-different-api-styles?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Styles</a></b></p><p class="paragraph" style="text-align:left;">Today, we will discuss one API style called GraphQL, we will look at how GraphQL works and the different components of GraphQL.</p><p class="paragraph" style="text-align:left;"><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">This comes from my </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a><span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;"> under the </span><a class="link" href="https://masteringbackend.com/hubs/backend-engineering/api-and-api-design?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">API and API Design</a> <span style="color:rgb(45, 45, 45);font-family:Helvetica, Arial, sans-serif;font-size:16px;">section. However, I’m only transferring the knowledge here and breaking it down in this series one topic at a time.</span></p><h2 class="heading" style="text-align:left;" id="how-does-graph-ql-work">How Does GraphQL Work?</h2><p class="paragraph" style="text-align:left;">In modern APIs, GraphQL has emerged as a powerful alternative to REST, offering flexibility, efficiency, and precise data retrieval. Developed by Facebook in 2012 and open-sourced in 2015, GraphQL addresses many limitations of traditional API design.</p><h3 class="heading" style="text-align:left;" id="the-basics-of-graph-ql">The Basics of GraphQL</h3><p class="paragraph" style="text-align:left;">At its core, <b>GraphQL</b> is a query language and runtime for APIs. Unlike REST, which exposes multiple endpoints for different resources, GraphQL consolidates everything into a single endpoint. </p><p class="paragraph" style="text-align:left;">Clients send queries to this endpoint, specifying exactly what data they need, and the server responds with precisely that data. This eliminates the issues of <b>overfetching</b> (retrieving unnecessary data) and <b>underfetching</b> (requiring multiple requests to gather all needed data).</p><p class="paragraph" style="text-align:left;">For example, in a REST API, fetching a user’s details and their posts might require two endpoints:</p><ul><li><p class="paragraph" style="text-align:left;"><code>/users/:id</code></p></li><li><p class="paragraph" style="text-align:left;"><code>/users/:id/posts</code></p></li></ul><p class="paragraph" style="text-align:left;">In GraphQL, this can be achieved with a single query:</p><div class="codeblock"><pre><code>query &#123;
  user(id: 1) &#123;
    name
    email
    posts &#123;
      title
      content
    &#125;
  &#125;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">The server processes this query and returns only the requested fields in a structured JSON format:</p><div class="codeblock"><pre><code>&#123;
  &quot;data&quot;: &#123;
    &quot;user&quot;: &#123;
      &quot;name&quot;: &quot;Jane Doe&quot;,
      &quot;email&quot;: &quot;jane.doe@example.com&quot;,
      &quot;posts&quot;: [
        &#123;
          &quot;title&quot;: &quot;GraphQL Basics&quot;,
          &quot;content&quot;: &quot;Understanding how GraphQL works...&quot;
        &#125;,
        &#123;
          &quot;title&quot;: &quot;Advanced GraphQL&quot;,
          &quot;content&quot;: &quot;Diving deeper into GraphQL queries...&quot;
        &#125;
      ]
    &#125;
  &#125;
&#125;</code></pre></div><h2 class="heading" style="text-align:left;" id="the-anatomy-of-graph-ql">The Anatomy of GraphQL</h2><p class="paragraph" style="text-align:left;">To understand how GraphQL works, it’s important to break it down into its key components:</p><ol start="1"><li><p class="paragraph" style="text-align:left;">Schema</p></li><li><p class="paragraph" style="text-align:left;">Query</p></li><li><p class="paragraph" style="text-align:left;">Resolvers</p></li><li><p class="paragraph" style="text-align:left;">Mutations</p></li></ol><h3 class="heading" style="text-align:left;" id="schema">Schema</h3><p class="paragraph" style="text-align:left;">The schema is the backbone of a GraphQL API. It defines the structure of the data available through the API, including the types of resources and their relationships. Think of it as a contract between the client and the server.</p><p class="paragraph" style="text-align:left;">Example of a simple schema for a blog application:</p><div class="codeblock"><pre><code>type User &#123;
  id: ID!
  name: String!
  email: String!
  posts: [Post]
&#125;

type Post &#123;
  id: ID!
  title: String!
  content: String!
  author: User
&#125;

type Query &#123;
  user(id: ID!): User
  posts: [Post]
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">The schema can be the same with your database table fields or any data you want to expose to the Frontend.</p><h3 class="heading" style="text-align:left;" id="query">Query</h3><p class="paragraph" style="text-align:left;">Clients use GraphQL queries to request data. The query language is flexible and allows clients to specify exactly what fields they need.</p><p class="paragraph" style="text-align:left;">Here’s an example of a Query:</p><div class="codeblock"><pre><code>query &#123;
  posts &#123;
    title
    author &#123;
      name
    &#125;
  &#125;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">This query is exactly what your Frontend engineer will send to the backend to retrieve data. From this query, it is clear that the Frontend is looking to retrieve a collection of posts with the title and the author&#39;s name.</p><p class="paragraph" style="text-align:left;">The server returns only the requested fields:</p><div class="codeblock"><pre><code>&#123;
  &quot;data&quot;: &#123;
    &quot;posts&quot;: [
      &#123;
        &quot;title&quot;: &quot;GraphQL Basics&quot;,
        &quot;author&quot;: &#123;
          &quot;name&quot;: &quot;Jane Doe&quot;
        &#125;
      &#125;,
      &#123;
        &quot;title&quot;: &quot;Advanced GraphQL&quot;,
        &quot;author&quot;: &#123;
          &quot;name&quot;: &quot;John Smith&quot;
        &#125;
      &#125;
    ]
  &#125;
&#125;</code></pre></div><h3 class="heading" style="text-align:left;" id="resolvers">Resolvers</h3><p class="paragraph" style="text-align:left;">Resolvers are functions on the server side that fetch the actual data for the fields requested in the query. They connect the GraphQL API to the data sources, such as databases or other APIs. This is where your backend logic happens.</p><p class="paragraph" style="text-align:left;">Example resolver for a <code>user</code> query:</p><div class="codeblock"><pre><code>const resolvers = &#123;
  Query: &#123;
    user: (parent, args, context) =&gt; &#123;
      return context.db.getUserById(args.id);
    &#125;
  &#125;
&#125;;</code></pre></div><p class="paragraph" style="text-align:left;">The resolver above resolves the query when the Frontend requests a user detail. It finds the user via the ID specified and returns it to the Frontend as a response.</p><h3 class="heading" style="text-align:left;" id="mutations">Mutations</h3><p class="paragraph" style="text-align:left;">While queries fetch data, <b>mutations</b> modify it. Mutations allow clients to perform operations like creating, updating, or deleting data. Inside the resolver explained above, you can also define a Mutation object to resolve all the mutations that will be created in your backend.</p><p class="paragraph" style="text-align:left;">Here’s an example for your backend:</p><div class="codeblock"><pre><code>const resolvers = &#123;
  Mutation: &#123;
    addPost: (parent, args, context) =&gt; &#123;
      return context.db.addPost(args.title, args.content);
    &#125;
  &#125;
&#125;;</code></pre></div><p class="paragraph" style="text-align:left;">Example mutation to add a new post:</p><div class="codeblock"><pre><code>mutation &#123;
  addPost(title: &quot;New GraphQL Post&quot;, content: &quot;GraphQL is amazing!&quot;) &#123;
    id
    title
  &#125;
&#125;</code></pre></div><p class="paragraph" style="text-align:left;">The server responds with the newly created post:</p><div class="codeblock"><pre><code>&#123;
  &quot;data&quot;: &#123;
    &quot;addPost&quot;: &#123;
      &quot;id&quot;: &quot;101&quot;,
      &quot;title&quot;: &quot;New GraphQL Post&quot;
    &#125;
  &#125;
&#125;</code></pre></div><h4 class="heading" style="text-align:left;" id="key-features-and-benefits-of-graph-">Key Features and Benefits of GraphQL</h4><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Flexible Queries: </b>Clients can request only the data they need, reducing overfetching and underfetching.</p></li><li><p class="paragraph" style="text-align:left;"><b>Single Endpoint: </b>GraphQL APIs consolidate all resources into a single endpoint, simplifying client-side development.</p></li><li><p class="paragraph" style="text-align:left;"><b>Strong Typing: </b>The schema provides a clear contract, ensuring clients and servers understand the data structure.</p></li><li><p class="paragraph" style="text-align:left;"><b>Real-Time Capabilities: </b>With <b>subscriptions</b>, GraphQL can handle real-time updates, making it suitable for dynamic applications like chat apps or live dashboards.</p></li><li><p class="paragraph" style="text-align:left;"><b>Tooling and Ecosystem: </b>GraphQL’s introspection capabilities enable powerful developer tools like <b>GraphiQL</b> and <b>Apollo Client</b> to test and interact with APIs.</p></li></ol><h4 class="heading" style="text-align:left;" id="challenges-of-graph-ql">Challenges of GraphQL</h4><p class="paragraph" style="text-align:left;">While GraphQL offers numerous advantages, it’s not without challenges:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><b>Complexity in Implementation</b>: Setting up resolvers and schema can be more complex than a REST API.</p></li><li><p class="paragraph" style="text-align:left;"><b>Overhead for Simple Use Cases</b>: For straightforward APIs, GraphQL might be overkill.</p></li><li><p class="paragraph" style="text-align:left;"><b>Query Performance</b>: Complex nested queries can lead to performance issues if not optimized.</p></li></ol><p class="paragraph" style="text-align:left;">GraphQL is revolutionizing the way APIs are designed and consumed, offering unparalleled flexibility and precision in data retrieval. Its ability to empower clients to shape their data needs makes it ideal for modern, dynamic applications. While it’s not a silver bullet, understanding how GraphQL works and when to use it can help developers build more efficient and scalable APIs.</p><hr class="content_break"><p class="paragraph" style="text-align:left;"><b>Did you learn any new things from this newsletter this week? Please reply to this email and let me know. Feedback like this encourages me to keep going.</b></p><p class="paragraph" style="text-align:left;">See you on Next Week.</p><p class="paragraph" style="text-align:left;">Remember to start learning backend engineering from our courses:</p><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-nodejs-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Node.js Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-rust-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Rust Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-python-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Python Backend Engineer is Live</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses/become-a-java-spring-backend-engineer?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Become a Java + Spring Backend Engineer is Live</a></p></li></ol><hr class="content_break"><h2 class="heading" style="text-align:left;" id="top-5-remote-backend-jobs-this-week">Top 5 Remote Backend Jobs this week</h2><p class="paragraph" style="text-align:left;">Here are the top 5 Backend Jobs you can apply to now.</p><p class="paragraph" style="text-align:left;">👨‍💻 Flying Bisons<br>✍️<b> Backend Developer</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-ZrWh6E?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Automattic Inc<br>✍️ <b>Backend Software Engineer</b><br>📍Remote, <i>Worldwide</i><br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-software-engineer-parsely-PHK0D9?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 homepage<br>✍️ <b>Backend Developer PHP</b><br>📍Remote, Worldwide<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-developer-php-TUnrgK?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">👨‍💻 Constructor<br>✍️<b> Backend Engineer: Search Features & APIs (Remote)</b><br>📍Remote<br>💰 Click on Apply for salary details<br><a class="link" href="https://getbackendjobs.com/jobs/backend-engineer-search-features-and-apis-remote-VkFAjo?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Click here to Apply for this role.</a></p><p class="paragraph" style="text-align:left;">Want more <b>Remote Backend Jobs</b>? Visit <a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs.com</a></p><hr class="content_break"><h2 class="heading" style="text-align:left;" id="backend-engineering-resources"><b>Backend Engineering Resources</b></h2><ol start="1"><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/hubs/backend-engineering?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Hub</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/books?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">All Backend Books</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://store.masteringbackend.com/?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Visit our Backend Store</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/community?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Join our Community</a></p></li><li><p class="paragraph" style="text-align:left;"><a class="link" href="https://masteringbackend.com/courses?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Backend Engineering Courses</a></p></li></ol><hr class="content_break"><div class="section" style="background-color:#F4FAFE;border-radius:5px;margin:0.0px 0.0px 0.0px 0.0px;padding:5.0px 5.0px 5.0px 5.0px;"><h3 class="heading" style="text-align:left;"><b>Whenever you&#39;re ready</b></h3><p class="paragraph" style="text-align:left;"><b>There are 4 ways I can help you become a great backend engineer:</b></p><p class="paragraph" style="text-align:left;"><b>1.</b> <b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Platform:</a></b><b> </b>Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.</p><p class="paragraph" style="text-align:left;"><b>2. </b><b><a class="link" href="https://click.convertkit-mail4.com/4zuplwzlo3aeh5lkndnhxh3d3ml77/6qhehou7nrnkwlbo/aHR0cHM6Ly93d3cuanVzdGlud2Vsc2gubWUvdGhlLW9wZXJhdGluZy1zeXN0ZW0tZ3Jvdy1tb25ldGl6ZS15b3VyLWxpbmtlZGlu?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">​</a></b><b><a class="link" href="https://masteringbackend.com/academy?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">The MB Academy:​ </a></b>The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.</p><p class="paragraph" style="text-align:left;"><b>3. </b><b><a class="link" href="https://app.masteringbackend.com?utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">MB Video-Based Courses:</a></b> Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.</p><p class="paragraph" style="text-align:left;"><b>4. </b><b><a class="link" href="https://getbackendjobs.com?ref=backend-weekly&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">GetBackendJobs:</a></b> Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.</p><p class="paragraph" style="text-align:left;"></p></div><hr class="content_break"><p class="paragraph" style="text-align:left;"><span style="color:rgb(0, 17, 255);"><b>LAST WORD </b></span>👋 </p><p class="paragraph" style="text-align:left;"><b>How am I doing?</b></p><p class="paragraph" style="text-align:left;">I love hearing from readers, and I&#39;m always looking for feedback. How am I doing with The Backend Weekly? Is there anything you&#39;d like to see more or less of? Which aspects of the newsletter do you enjoy the most?</p><p class="paragraph" style="text-align:left;">Hit reply and say hello - I&#39;d love to hear from you!</p><div class="image"><img alt="" class="image__image" style="border-radius:1000px 1000px 1000px 1000px;border-style:dotted;border-width:0px 0px 0px 0px;box-sizing:border-box;border-color:#E5E7EB;" src="https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/17ad43c8-9caf-4191-8379-b457729a4d90/solomon-eseme.jpg?t=1714830814"/></div><p class="paragraph" style="text-align:left;">Stay awesome,<br>Solomon</p><p class="paragraph" style="text-align:left;"><i>I moved my newsletter from Substack to Beehiiv, and it&#39;s been an amazing journey. </i><i><a class="link" href="https://www.beehiiv.com/?via=kap&utm_source=newsletter.masteringbackend.com&utm_medium=newsletter&utm_campaign=api-and-api-design-how-graphql-apis-work" target="_blank" rel="noopener noreferrer nofollow">Start yours here.</a></i></p></div><div class='beehiiv__footer'><br class='beehiiv__footer__break'><hr class='beehiiv__footer__line'><a target="_blank" class="beehiiv__footer_link" style="text-align: center;" href="https://www.beehiiv.com/?utm_campaign=c5153a5f-96d4-42b6-9cbb-7f5be012f1ee&utm_medium=post_rss&utm_source=backend_weekly">Powered by beehiiv</a></div></div>
  ]]></content:encoded>
</item>

  </channel>
</rss>
