<?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: Bhautik</title>
    <description>The latest articles on DEV Community by Bhautik (@bhautik_livingswiss).</description>
    <link>https://dev.to/bhautik_livingswiss</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4158206%2F4b7f3722-4e45-4e41-aa65-e7ab376994e1.png</url>
      <title>DEV Community: Bhautik</title>
      <link>https://dev.to/bhautik_livingswiss</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhautik_livingswiss"/>
    <language>en</language>
    <item>
      <title>Building a Zero-Lag Swiss Tax &amp; Salary Calculator in Next.js (Why We Kept Everything in Browser Memory)</title>
      <dc:creator>Bhautik</dc:creator>
      <pubDate>Fri, 02 Oct 2026 17:50:58 +0000</pubDate>
      <link>https://dev.to/bhautik_livingswiss/building-a-zero-lag-swiss-tax-salary-calculator-in-nextjs-why-we-kept-everything-in-browser-49ee</link>
      <guid>https://dev.to/bhautik_livingswiss/building-a-zero-lag-swiss-tax-salary-calculator-in-nextjs-why-we-kept-everything-in-browser-49ee</guid>
      <description>&lt;p&gt;If you’ve ever looked at how taxes and social contributions work in Switzerland, you know it’s notoriously decentralized. &lt;/p&gt;

&lt;p&gt;There are 26 cantons, each with its own municipal tax multipliers (&lt;em&gt;Steuerfuss&lt;/em&gt;), varying church taxes, multiple withholding tax tariffs (Quellensteuer), and statutory pension rules that change based on your exact age bracket.&lt;/p&gt;

&lt;p&gt;When building &lt;a href="https://livingswiss.ch" rel="noopener noreferrer"&gt;LivingSwiss&lt;/a&gt;, an expat analytics and financial tool suite, our initial instinct was to treat this like a standard backend system: send the user's salary, canton, and civil status to an API route, calculate the numbers on a server, and return the JSON response.&lt;/p&gt;

&lt;p&gt;Here’s why we completely scrapped that architecture and why keeping 100% of the mathematical engine in the user's browser runtime was one of the best decisions we made.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. The Real-Time Slider Problem (Why Server Latency Kills UX)
&lt;/h3&gt;

&lt;p&gt;Financial calculators feel great to use when they react instantly. &lt;/p&gt;

&lt;p&gt;When an engineer or expat drags a salary slider from CHF 100,000 to CHF 150,000, they want to watch the pie chart segments and monthly take-home numbers fluidly shift in real time.&lt;/p&gt;

&lt;p&gt;If every slider tick fires an HTTP POST request across the wire:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You introduce an unavoidable 100ms–300ms network hop.&lt;/li&gt;
&lt;li&gt;You have to implement aggressive debouncing, which makes the UI feel sluggish.&lt;/li&gt;
&lt;li&gt;If 10,000 people use the tool at once, your server CPU spikes doing repetitive math.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By writing the calculation engine as pure, deterministic TypeScript functions with zero external dependencies, calculations execute in &lt;strong&gt;sub-1 millisecond&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The UI easily hits a locked 60 frames per second (sub-16ms render loop), even when simultaneously re-rendering complex SVG donut charts and multi-year pension projections.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. The Privacy Dividend: Zero Data Ever Leaves the Browser
&lt;/h3&gt;

&lt;p&gt;Salary and tax data is deeply personal. Nobody wants to type their exact compensation and dependent details into a random web app if they suspect it's being logged into a remote Postgres database or tracked by ad networks.&lt;/p&gt;

&lt;p&gt;Because our entire mathematical engine runs purely in local React state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Zero salary data is stored or transmitted.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;We can truthfully promise a 100% zero-storage privacy guarantee.&lt;/li&gt;
&lt;li&gt;Server operating costs stay virtually near zero even under heavy traffic spikes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. How the Engine Works Under the Hood
&lt;/h3&gt;

&lt;p&gt;Here’s a simplified look at how we structure the Gross-to-Net deduction pipeline in pure TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Deterministic calculation pipeline (0ms server latency)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateGrossToNet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gross&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;canton&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. First Pillar Social Security (AVS/AI/APG - 5.30%)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;avs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gross&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.053&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Unemployment Insurance (1.10% capped at CHF 148,200)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ac&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gross&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;148200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.011&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 3. Second Pillar BVG Pension (Art. 8 &amp;amp; 16 BVG Coordination Math)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coordinationDeduction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25725&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;maxBvgSalary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;88200&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;coordinatedSalary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gross&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxBvgSalary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;coordinationDeduction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Age-graded employee contribution rates&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bvgRate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;0.035&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;0.050&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;55&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;0.075&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.090&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;bvg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;coordinatedSalary&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;bvgRate&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 4. Net take-home before cantonal withholding tax&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;netBeforeTax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gross&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;avs&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ac&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;bvg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;gross&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;avs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;ac&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;bvg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;netBeforeTax&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;monthlyTakeHome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;netBeforeTax&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&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;By decoupling pure math from UI components, the engine is fully unit-testable in isolation (verify-salary-engine.ts), while our Next.js frontend simply maps the output numbers to localized typography and SVG charts.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Mathematical Accuracy Over Assumptions
&lt;/h3&gt;

&lt;p&gt;One of the biggest flaws we noticed in older web calculators was how they mishandled foreign resident taxes.&lt;/p&gt;

&lt;p&gt;Swiss citizens file ordinary tax returns at year-end, while foreign workers on B/L work permits have statutory withholding tax (Quellensteuer) deducted directly from their monthly payroll. Applying the wrong model can easily throw off monthly take-home estimates by CHF 500–800.&lt;/p&gt;

&lt;p&gt;Grounding the engine directly in official Swiss Federal Statutes (Art. 83 DBG for withholding tax tariffs and Art. 8 &amp;amp; 16 BVG for pension coordination) ensured the numbers matched the exact centimes on real monthly payslips.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Wrapping Up
&lt;/h3&gt;

&lt;p&gt;Modern web development often pushes developers toward serverless functions and heavy cloud APIs. But for tools like financial visualizers, tax estimators, and interactive models, pure client-side computation in modern JavaScript/TypeScript is often faster, safer, and significantly cheaper to scale.&lt;/p&gt;

&lt;p&gt;If you’d like to see the live implementation in action, you can test the calculator here: &lt;a href="https://livingswiss.ch/calculators/salary-tax" rel="noopener noreferrer"&gt;LivingSwiss Swiss Salary &amp;amp; Tax Calculator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Would love to hear how other developers approach client-side vs. server-side math in their own projects!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
