<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khaja Hussain</title>
    <description>The latest articles on DEV Community by Khaja Hussain (@khaja_hussain_db1f84efe83).</description>
    <link>https://dev.to/khaja_hussain_db1f84efe83</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2560465%2Ffaf7ab2d-3413-4aac-84ad-22ef1c22b6c0.png</url>
      <title>DEV Community: Khaja Hussain</title>
      <link>https://dev.to/khaja_hussain_db1f84efe83</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khaja_hussain_db1f84efe83"/>
    <language>en</language>
    <item>
      <title>I Compared TOON vs Minified JSON Using OpenAI’s Tokenizer</title>
      <dc:creator>Khaja Hussain</dc:creator>
      <pubDate>Tue, 12 May 2026 00:29:29 +0000</pubDate>
      <link>https://dev.to/khaja_hussain_db1f84efe83/i-compared-toon-vs-minified-json-using-openais-tokenizer-31d0</link>
      <guid>https://dev.to/khaja_hussain_db1f84efe83/i-compared-toon-vs-minified-json-using-openais-tokenizer-31d0</guid>
      <description>&lt;p&gt;Recently I noticed a lot of developers talking about TOON:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/toon-format/toon" rel="noopener noreferrer"&gt;TOON GitHub repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea behind TOON is interesting. Instead of sending traditional JSON, TOON tries to reduce token usage and make data more compact for LLMs.&lt;/p&gt;

&lt;p&gt;Since token costs are becoming a real concern for AI products, I wanted to test it myself.&lt;/p&gt;

&lt;p&gt;Not theoretically.&lt;br&gt;
Not with benchmarks from slides.&lt;br&gt;
Just a simple real-world comparison.&lt;/p&gt;

&lt;p&gt;I used OpenAI’s tokenizer tool and compared:&lt;/p&gt;

&lt;p&gt;TOON format&lt;br&gt;
Minified JSON&lt;/p&gt;

&lt;p&gt;For the conversion process, I used:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.jsonparser.ai/json-to-toon/" rel="noopener noreferrer"&gt;JSON to TOON Converter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.jsonparser.ai/json-minifier/" rel="noopener noreferrer"&gt;JSON Minifier&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Minified JSON:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;{"user":{"id":1001,"name":"Khaja","email":"&lt;a href="mailto:khaja@example.com"&gt;khaja@example.com&lt;/a&gt;","roles":["admin","developer"],"settings":{"theme":"dark","notifications":true}}}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;TOON version:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;user:&lt;br&gt;
  id: 1001&lt;br&gt;
  name: Khaja&lt;br&gt;
  email: &lt;a href="mailto:khaja@example.com"&gt;khaja@example.com&lt;/a&gt;&lt;br&gt;
  roles[2]: admin,developer&lt;br&gt;
  settings:&lt;br&gt;
    theme: dark&lt;br&gt;
    notifications: true&lt;br&gt;
`&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;TOON Result&lt;/strong&gt;: Tokens: 37&lt;br&gt;
&lt;strong&gt;Minified JSON Result&lt;/strong&gt;: Tokens: 38&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkfpv9c3lrqg6uuiur4f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkfpv9c3lrqg6uuiur4f.png" alt=" " width="526" height="491"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qx4utouecdafrseyhp3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qx4utouecdafrseyhp3.png" alt=" " width="537" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That means TOON saved only 1 token in this example.&lt;/p&gt;

&lt;p&gt;Honestly, that surprised me.&lt;/p&gt;

&lt;p&gt;So… Is TOON Useful?&lt;/p&gt;

&lt;p&gt;I think the answer is: yes, but with nuance.&lt;/p&gt;

&lt;p&gt;TOON is not “bad.”&lt;br&gt;
In fact, I actually like the direction.&lt;/p&gt;

&lt;p&gt;It makes developers think seriously about:&lt;/p&gt;

&lt;p&gt;token efficiency&lt;br&gt;
AI-friendly data formats&lt;br&gt;
prompt optimization&lt;br&gt;
serialization overhead&lt;/p&gt;

&lt;p&gt;Those are important conversations.&lt;/p&gt;

&lt;p&gt;But after testing it, I’m not convinced that TOON alone will dramatically reduce costs for most companies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In many cases&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;removing whitespace already gives huge savings&lt;br&gt;
gzip/brotli compression already works extremely well&lt;br&gt;
AI models are already heavily trained on JSON structures&lt;/p&gt;

&lt;p&gt;So the practical gains may be smaller than the hype suggests.&lt;/p&gt;

&lt;p&gt;But Small Savings Can Still Matter at Scale&lt;/p&gt;

&lt;p&gt;Here’s the interesting part.&lt;/p&gt;

&lt;p&gt;Even tiny optimizations matter when companies process millions of requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Imagine&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;10 million API calls&lt;br&gt;
large AI prompts&lt;br&gt;
multiple agents&lt;br&gt;
long conversation histories&lt;/p&gt;

&lt;p&gt;Saving even 1–2% tokens at scale could potentially save hundreds or thousands of dollars over time.&lt;/p&gt;

&lt;p&gt;So I do understand why people are excited about TOON.&lt;/p&gt;

&lt;p&gt;The Bigger Challenge: Ecosystem&lt;/p&gt;

&lt;p&gt;Personally, I think TOON’s biggest challenge is not token count.&lt;/p&gt;

&lt;p&gt;It’s ecosystem adoption.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSON already has&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;mature tooling&lt;br&gt;
validators&lt;br&gt;
parsers&lt;br&gt;
database support&lt;br&gt;
IDE integrations&lt;br&gt;
API ecosystem dominance&lt;/p&gt;

&lt;p&gt;Replacing that is extremely difficult.&lt;/p&gt;

&lt;p&gt;In real production systems, compatibility usually matters more than tiny syntax improvements.&lt;/p&gt;

&lt;p&gt;My Take&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After testing both formats, my conclusion is&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;TOON introduces interesting ideas&lt;br&gt;
token savings appear modest in smaller examples&lt;br&gt;
the ecosystem challenge is massive&lt;br&gt;
but the conversation around AI-native serialization formats is valuable&lt;/p&gt;

&lt;p&gt;I don’t think JSON is disappearing anytime soon.&lt;/p&gt;

&lt;p&gt;But I do think experiments like TOON push the industry forward.&lt;/p&gt;

&lt;p&gt;And honestly, that’s a good thing.&lt;/p&gt;

&lt;p&gt;Would love to hear what other developers think or any suggestion what to compare next.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>ai</category>
    </item>
    <item>
      <title>A free, high-performance backend for small projects — Cloudflare Workers in 10 minutes</title>
      <dc:creator>Khaja Hussain</dc:creator>
      <pubDate>Sun, 03 May 2026 11:00:22 +0000</pubDate>
      <link>https://dev.to/khaja_hussain_db1f84efe83/a-free-high-performance-backend-for-small-projects-cloudflare-workers-in-10-minutes-4769</link>
      <guid>https://dev.to/khaja_hussain_db1f84efe83/a-free-high-performance-backend-for-small-projects-cloudflare-workers-in-10-minutes-4769</guid>
      <description>&lt;p&gt;Every developer wants the same thing: a free way to run small backend tasks. A webhook for a side project. A contact form handler. An OG image generator. A small proxy to hide an API key. Things that handle a few hundred requests a week. They do not need a $20/month server, an Azure Function App you will forget about next month, or a new Lambda that takes an hour to set up.&lt;/p&gt;

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

&lt;p&gt;I have had this problem for years. Most of my work is in .NET shops — AWS for production, Azure for clients on the Microsoft stack. Both are great for real workloads. Both feel like overkill when the actual task is "send me an email when a Stripe customer pays."&lt;/p&gt;

&lt;p&gt;Last weekend I needed exactly that webhook. Spinning up a new Function App for one endpoint felt silly. Adding it to an existing production API would mix two unrelated things — the next person reading the code would wonder why a billing handler was sitting inside the customer-facing app. Every option I knew was way too much setup for one tiny task.&lt;/p&gt;

&lt;p&gt;So I finally tried something I had been avoiding for three years: &lt;strong&gt;&lt;a href="https://workers.cloudflare.com/" rel="noopener noreferrer"&gt;Cloudflare Workers&lt;/a&gt;.&lt;/strong&gt; It solved the problem in ten minutes. Free, no credit card, deployed to 300+ data centres. Here is how it went, and why I should have tried it sooner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I had been ignoring Cloudflare Workers
&lt;/h2&gt;

&lt;p&gt;Three reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No .NET story.&lt;/strong&gt; I work in C#. Writing JavaScript at the edge felt like a whole new world just to deploy one small function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The marketing made it look like big-company infra.&lt;/strong&gt; Every Workers post I had read mentioned Durable Objects, R2, KV, Queues, AI bindings. It looked like a big platform you commit to, not a tool you grab for one task.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I thought the free tier was a trick.&lt;/strong&gt; "100,000 requests per day" sounded like a number with hidden conditions and a credit-card requirement.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of those were true.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 10 minutes
&lt;/h2&gt;

&lt;p&gt;Install &lt;a href="https://developers.cloudflare.com/workers/wrangler/install-and-update/" rel="noopener noreferrer"&gt;Wrangler&lt;/a&gt;, the Cloudflare CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; wrangler
wrangler login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The login opens a browser. Click approve and you are done. No credit card asked. I checked twice — I have been burned before.&lt;/p&gt;

&lt;p&gt;Scaffold a project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create cloudflare@latest stripe-webhook
&lt;span class="nb"&gt;cd &lt;/span&gt;stripe-webhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pick "Hello World" Worker, JavaScript, skip the deploy step. The generator puts everything in one folder. Open &lt;code&gt;src/index.js&lt;/code&gt; and replace the default code with this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST only&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;405&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Invalid JSON&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkout.session.completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amount_total&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;customer_email&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.resend.com/emails&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;RESEND_KEY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alerts@mydomain.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;me@mydomain.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`New payment: $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; just paid $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;span class="c"&gt;# Ready on http://localhost:8787&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Send a fake Stripe payload with curl. Worked on the first try.&lt;/p&gt;

&lt;p&gt;Deploy it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx wrangler deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eight seconds later it printed a &lt;code&gt;*.workers.dev&lt;/code&gt; URL. Total bundle size: 1.2 KB. I pointed Stripe's webhook config at that URL, sent a test event from the Stripe dashboard, and the email arrived in my inbox before the dashboard finished refreshing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part that surprised me
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://developers.cloudflare.com/workers/platform/limits/" rel="noopener noreferrer"&gt;free tier&lt;/a&gt; really is 100,000 requests a day. No credit card. The Worker runs in 300+ Cloudflare data centres at the same time. A Stripe webhook from San Francisco hits the San Jose data centre, my email goes out from Resend's nearest server, and the whole round trip takes under 200ms. No cold start. No Function App I have to remember to delete next month before it starts billing me.&lt;/p&gt;

&lt;p&gt;If you store a webhook secret with &lt;code&gt;wrangler secret put STRIPE_WEBHOOK_SECRET&lt;/code&gt; and verify the signature (you should — Stripe sends a &lt;a href="https://stripe.com/docs/webhooks/signatures" rel="noopener noreferrer"&gt;&lt;code&gt;Stripe-Signature&lt;/code&gt;&lt;/a&gt; header for this), the whole thing is still about 60 lines of code.&lt;/p&gt;

&lt;h2&gt;
  
  
  One gotcha worth knowing
&lt;/h2&gt;

&lt;p&gt;If the request body is invalid JSON, &lt;code&gt;request.json()&lt;/code&gt; throws a &lt;code&gt;SyntaxError&lt;/code&gt; and Cloudflare returns a generic 500. That is bad for any user-facing endpoint, and it is worse for Stripe — Stripe retries on 5xx errors, so a broken parser quietly turns into duplicate retries while your dashboard looks fine. Wrap the parse in a try/catch and return a 400 with a clear message. Stripe webhook payloads are also big and hard to read; pretty-printing them with a &lt;a href="https://jsonparser.ai/json-formatter" rel="noopener noreferrer"&gt;JSON formatter&lt;/a&gt; makes debugging much faster. I learned the try/catch lesson the hard way — one panicked late-night Stripe dashboard refresh.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently next time
&lt;/h2&gt;

&lt;p&gt;Use Workers first for any small task that needs an HTTP endpoint. That is a much bigger category than just "webhook" — link shorteners, OG image generators, form handlers, edge auth, JSON proxies, internal Slack bots. Trying it is one &lt;code&gt;npm create&lt;/code&gt; command away.&lt;/p&gt;

&lt;p&gt;I feel a bit silly for waiting three years. The mental model is one sentence: a Worker is a function that takes a &lt;code&gt;Request&lt;/code&gt; and returns a &lt;code&gt;Response&lt;/code&gt;. That is the whole platform. Everything else (KV, Durable Objects, AI bindings) is optional. If you want the full step-by-step instead of the highlights here, &lt;a href="https://jsonparser.ai/blog/json/deploy-free-json-api-cloudflare-workers" rel="noopener noreferrer"&gt;this Cloudflare Workers deploy guide&lt;/a&gt; covers the whole setup with a real validating endpoint, the free-tier limits in detail, and a few more gotchas to know before you ship.&lt;/p&gt;

&lt;p&gt;If you have been avoiding Workers like I was, try it on the next small task you hit. Fifteen minutes will tell you if it fits how you think. For me, it did.&lt;/p&gt;

</description>
      <category>backend</category>
    </item>
    <item>
      <title>Understanding Protocol Buffers: A Fast Alternative to JSON</title>
      <dc:creator>Khaja Hussain</dc:creator>
      <pubDate>Sun, 15 Dec 2024 20:36:23 +0000</pubDate>
      <link>https://dev.to/khaja_hussain_db1f84efe83/understanding-protocol-buffers-a-fast-alternative-to-json-ga2</link>
      <guid>https://dev.to/khaja_hussain_db1f84efe83/understanding-protocol-buffers-a-fast-alternative-to-json-ga2</guid>
      <description>&lt;p&gt;In the world of data interchange, JSON (JavaScript Object Notation) has been a long-standing favourite. It’s simple, human-readable, and works seamlessly across platforms. For many use cases, JSON is “good enough.” But as systems scale, and the need for speed and efficiency increases, JSON’s text-based format can become a bottleneck.&lt;/p&gt;

&lt;p&gt;That’s where Protocol Buffers (Protobuf) come in. Developed by Google, Protobuf is a powerful, compact, and lightning-fast data serialization format that has become a popular choice for modern applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Consider Protocol Buffers Over JSON?&lt;/strong&gt;&lt;br&gt;
Compactness: JSON’s text-based format can result in larger payloads. Protobuf, on the other hand, uses a binary format, which dramatically reduces the size of the data.&lt;/p&gt;

&lt;p&gt;Speed: Protobuf’s binary format is faster to serialize (convert data to a transferable format) and deserialize (convert back to usable data).&lt;/p&gt;

&lt;p&gt;Schema Evolution: Protobuf includes a schema that defines the structure of your data, making it easier to evolve your APIs without breaking backward compatibility.&lt;/p&gt;

&lt;p&gt;Efficiency at Scale: For applications with high traffic or limited bandwidth (e.g., mobile apps, IoT devices), Protobuf’s efficiency can result in lower latency and better performance.&lt;/p&gt;

&lt;p&gt;Protocol Buffers: A Smarter Way to Handle Data&lt;br&gt;
In the world of data interchange, JSON (JavaScript Object Notation) has been a long-standing favorite. It’s simple, human-readable, and works seamlessly across platforms. For many use cases, JSON is “good enough.” But as systems scale, and the need for speed and efficiency increases, JSON’s text-based format can become a bottleneck.&lt;/p&gt;

&lt;p&gt;That’s where Protocol Buffers (Protobuf) come in. Developed by Google, Protobuf is a powerful, compact, and lightning-fast data serialization format that has become a popular choice for modern applications.&lt;/p&gt;

&lt;p&gt;Why Consider Protocol Buffers Over JSON?&lt;br&gt;
Compactness: JSON’s text-based format can result in larger payloads. Protobuf, on the other hand, uses a binary format, which dramatically reduces the size of the data.&lt;/p&gt;

&lt;p&gt;Speed: Protobuf’s binary format is faster to serialize (convert data to a transferable format) and deserialize (convert back to usable data).&lt;/p&gt;

&lt;p&gt;Schema Evolution: Protobuf includes a schema that defines the structure of your data, making it easier to evolve your APIs without breaking backward compatibility.&lt;/p&gt;

&lt;p&gt;Efficiency at Scale: For applications with high traffic or limited bandwidth (e.g., mobile apps, IoT devices), Protobuf’s efficiency can result in lower latency and better performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Quick Comparison: JSON vs. Protobuf&lt;/strong&gt;&lt;br&gt;
Let’s take a simple example. Imagine you’re sending information about a user:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using JSON:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": 123,
  "name": "John Doe",
  "email": "john.doe@example.com"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is straightforward and human-readable. But it’s also relatively large because of all the extra characters like {}, :, and the field names.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Protobuf:&lt;/strong&gt;&lt;br&gt;
First, you define a schema (usually in a .proto file):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When serialized to binary format, this same data is compacted into a tiny, efficient payload—unreadable to humans but incredibly fast for computers to process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to Stick with JSON&lt;/strong&gt;&lt;br&gt;
JSON is still a fantastic choice for many use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If human-readability is a priority (e.g., logging or configuration files).&lt;/li&gt;
&lt;li&gt;For simple, low-traffic systems where performance isn’t critical.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to Use Protobuf&lt;/strong&gt;&lt;br&gt;
If your application needs to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle large-scale data exchange (e.g., microservices, real-time APIs).&lt;/li&gt;
&lt;li&gt;Operate under bandwidth constraints (e.g., mobile or IoT devices).&lt;/li&gt;
&lt;li&gt;Ensure compatibility while evolving the API schema.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JSON is like the comfortable, everyday car you drive around town—reliable and easy to use. Protobuf, on the other hand, is a sleek sports car—designed for speed, efficiency, and high performance. While JSON is great for most day-to-day tasks, Protobuf shines when you need to go the extra mile.&lt;/p&gt;

&lt;p&gt;So, whether you stick with JSON or make the leap to Protobuf depends on your needs. But if you’re building for the future and performance is key, Protobuf is a solid choice to keep things running smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some helpful links to understand Protobuf and Json:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://protobuf.dev/" rel="noopener noreferrer"&gt;Protocol Buffers Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/protocolbuffers/protobuf" rel="noopener noreferrer"&gt;protobuf&lt;/a&gt;&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/JSON" rel="noopener noreferrer"&gt;Json&lt;/a&gt;&lt;br&gt;
&lt;a href="https://jsontotable.org/Blog/Api-development.html" rel="noopener noreferrer"&gt;JSON in API Development&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
