<?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>Forem: derekzyl</title>
    <description>The latest articles on Forem by derekzyl (@derekzyl).</description>
    <link>https://forem.com/derekzyl</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%2F405849%2F6b5dc344-8b45-4794-b005-8366c648877c.png</url>
      <title>Forem: derekzyl</title>
      <link>https://forem.com/derekzyl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/derekzyl"/>
    <language>en</language>
    <item>
      <title># How I Fixed Our Auth Bottleneck: From Some Seconds to Instant</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Thu, 09 Oct 2025 22:25:00 +0000</pubDate>
      <link>https://forem.com/derekzyl/-how-i-fixed-our-auth-bottleneck-from-some-seconds-to-instant-4g6g</link>
      <guid>https://forem.com/derekzyl/-how-i-fixed-our-auth-bottleneck-from-some-seconds-to-instant-4g6g</guid>
      <description>&lt;p&gt;Last week, our cart operations were taking 18+ seconds. Not minutes—seconds. Each time a user added something to their cart, they'd wait nearly 20 seconds staring at a loading spinner. Meanwhile, our public pages? Lightning fast.&lt;/p&gt;

&lt;p&gt;Something was very, very wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the Problem
&lt;/h2&gt;

&lt;p&gt;The weird part was the inconsistency. Public endpoints responded in milliseconds. But anything requiring authentication? Painful. I pulled up the network inspector and there it was—18.72 seconds spent "waiting for server response."&lt;/p&gt;

&lt;p&gt;Not network latency. Not a slow database query. The auth middleware itself was the bottleneck.&lt;/p&gt;

&lt;p&gt;Here's the thing—I'd already spent weeks optimizing every route. Added indexes, optimized queries, used &lt;code&gt;.lean()&lt;/code&gt; for read operations, implemented proper pagination. The cart service? Optimized. The wishlist endpoints? Optimized. Product queries? All good.&lt;/p&gt;

&lt;p&gt;But none of that mattered because the auth middleware was running before every single route, killing performance before my optimized code even got a chance to run.&lt;/p&gt;

&lt;p&gt;Here's what was happening on every single authenticated request:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;verifyCallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ... auth checks ...&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;roles&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;ROLES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// Hit the database&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapRoles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

  &lt;span class="k"&gt;for &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;role&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Another database hit for EACH role&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;convertPermissionIdsToNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;mapRoles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// ... permission checking ...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every. Single. Request.&lt;/p&gt;

&lt;p&gt;For a system where roles and permissions rarely change (maybe once a month?), we were hammering the database constantly. Classic N+1 query problem, running on every auth check.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fix: Three Layers of Caching
&lt;/h2&gt;

&lt;p&gt;I needed speed without breaking things. The solution was a three-tier cache:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tier 1: Local Memory&lt;/strong&gt; (~0.1ms)&lt;br&gt;&lt;br&gt;
Keep permissions in memory for 10 minutes. Fastest possible access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tier 2: Redis&lt;/strong&gt; (~1-5ms)&lt;br&gt;&lt;br&gt;
Shared across all server instances, lasts 24 hours. Fast enough and handles scaling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tier 3: Database&lt;/strong&gt; (~100-500ms)&lt;br&gt;&lt;br&gt;
Only when both caches miss, which is rare after the first request.&lt;/p&gt;

&lt;p&gt;Here's how it flows:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;buildRolePermissionsCache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Try local memory first&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRolePermissionsFromLocalCache&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;permissions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Try Redis next&lt;/span&gt;
  &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getRolePermissionsFromRedis&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;permissions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setRolePermissionsToLocalCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Fine, hit the database&lt;/span&gt;
  &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;buildRolePermissionsFromDatabase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="c1"&gt;// Cache it everywhere for next time&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;setRolePermissionsToRedis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;setRolePermissionsToLocalCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;permissions&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;The local cache implementation is dead simple:&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;localRolePermissionsCache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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;localCacheTimestamp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;LOCAL_CACHE_DURATION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 10 minutes&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getRolePermissionsFromLocalCache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&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;localRolePermissionsCache&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; 
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;localCacheTimestamp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;LOCAL_CACHE_DURATION&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="nx"&gt;localRolePermissionsCache&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="kc"&gt;null&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;Nothing fancy. Just a variable, a timestamp, and a TTL check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing the Database Queries Too
&lt;/h2&gt;

&lt;p&gt;While I was in there, I also optimized how we fetch from the database when we do need to:&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="c1"&gt;// Before: Sequential queries&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;roles&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;ROLES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;for &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;role&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;roles&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;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getPermissions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// After: Parallel queries with a lookup map&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="nx"&gt;ROLES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;lean&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="nx"&gt;PERMISSIONS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;lean&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;permissionMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;perm&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;permissionMap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;perm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;perm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Now O(1) lookups instead of O(n) database queries&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.lean()&lt;/code&gt; calls help too—they skip Mongoose's document hydration, which we don't need for read-only operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Wins Along the Way
&lt;/h2&gt;

&lt;p&gt;While debugging, I found another issue: we were calculating shipping fees on every cart operation. That meant address lookups, shipping API calls, all for something the user doesn't see until checkout.&lt;/p&gt;

&lt;p&gt;Quick fix:&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="c1"&gt;// Before&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;defaultAddress&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;addressService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUserDefaultAddress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userId&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;defaultAddress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;shippingFee&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;shippingService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getShippingFee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;defaultAddress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// After&lt;/span&gt;
&lt;span class="nx"&gt;shippingFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Calculate at checkout instead&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Saved another few hundred milliseconds per request.&lt;/p&gt;

&lt;p&gt;I also added some database indexes that were missing:&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="nx"&gt;cartItemSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;cartId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;cartSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;wishlistSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;index&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These should have been there from day one, honestly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Results
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;First authenticated request:&lt;/strong&gt; 100-500ms (cold cache, hits database)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Every request after that:&lt;/strong&gt; ~0.1ms (local cache hit)&lt;/p&gt;

&lt;p&gt;Cart operations went from 18 seconds to under half a second. Wishlist operations saw similar improvements. The entire app feels snappier.&lt;/p&gt;

&lt;p&gt;Best part? The cache stays warm across requests, so most users never hit the slow path. And when roles/permissions do change (rarely), I just call:&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;await&lt;/span&gt; &lt;span class="nf"&gt;clearRolePermissionsCache&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both caches get wiped, next request rebuilds them, life goes on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Profile before optimizing.&lt;/strong&gt; I almost started optimizing database queries before realizing auth was the real problem. The network inspector saved me days of wasted effort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cache aggressively when data is stable.&lt;/strong&gt; Roles and permissions change maybe once a month. There's no reason to query them thousands of times per hour.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multiple cache tiers aren't overkill.&lt;/strong&gt; Local memory for speed, Redis for scaling, database as fallback. Each serves a purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't over-engineer early.&lt;/strong&gt; I added monitoring and stats later, once the basic caching worked. Getting it working first, then making it observable, was the right order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Indices matter.&lt;/strong&gt; Seriously, if you're doing &lt;code&gt;Model.find({ userId })&lt;/code&gt; frequently, just add the damn index.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;Everything's in production now. The local cache is stupid simple—just a variable and a timestamp. Redis handles the cross-instance sharing. The database is the fallback that rarely gets hit.&lt;/p&gt;

&lt;p&gt;If you're dealing with similar auth slowdowns, the pattern is pretty straightforward: identify what rarely changes, cache it aggressively, and only invalidate when it actually changes.&lt;/p&gt;

&lt;p&gt;And always, always profile first. I wasted an afternoon optimizing database queries that weren't the problem. The network inspector pointed straight at auth middleware within five minutes.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;P.S. If you're warming up the cache on server startup, do it after MongoDB connects but before accepting requests. Learned that one the hard way.&lt;/em&gt;&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="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mongoUrl&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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;warmUpAuthCache&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Do this first&lt;/span&gt;
  &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// Then start accepting traffic&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>architecture</category>
      <category>backend</category>
      <category>performance</category>
    </item>
    <item>
      <title>The Advantages of Learning Typed Languages for Beginners</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Thu, 28 Sep 2023 03:49:57 +0000</pubDate>
      <link>https://forem.com/derekzyl/the-advantages-of-learning-typed-languages-for-beginners-1n28</link>
      <guid>https://forem.com/derekzyl/the-advantages-of-learning-typed-languages-for-beginners-1n28</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Programming is an essential skill in today's tech-driven world, and one of the first decisions aspiring programmers face is whether to start with a typed or loosely typed programming language. Typed languages, where variables have specific data types, offer several advantages for beginners. In this article, we will explore the benefits of learning typed languages over loosely typed ones for newcomers to the world of programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error Detection and Prevention
&lt;/h2&gt;

&lt;p&gt;Typed languages, like Java or C++, require you to specify the data type of a variable when you declare it. This enforced typing helps catch errors at compile-time rather than runtime. As a beginner, this means you'll receive immediate feedback about type-related issues, making it easier to identify and correct errors early in the development process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Improved Code Readability
&lt;/h2&gt;

&lt;p&gt;Typed languages promote better code readability. When you declare variables with explicit data types, it becomes easier for both you and other developers to understand the purpose and expected values of those variables. This clarity can lead to more maintainable and collaborative coding projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stronger Debugging Tools
&lt;/h2&gt;

&lt;p&gt;Typed languages often come with robust integrated development environments (IDEs) and debugging tools. These tools leverage type information to provide intelligent code suggestions, auto-completion, and real-time error highlighting. For beginners, these features can be incredibly helpful in speeding up the learning process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduced Ambiguity
&lt;/h2&gt;

&lt;p&gt;In loosely typed languages like JavaScript or Python, variable types can change dynamically, leading to unexpected behavior if not managed carefully. Typed languages, on the other hand, reduce ambiguity by enforcing strict type rules, helping beginners avoid subtle bugs caused by type mismatches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhanced Learning Experience
&lt;/h2&gt;

&lt;p&gt;Learning typed languages can provide a structured and systematic approach to programming. As beginners, you'll gain a deeper understanding of data types, variable scope, and type-related concepts, setting a strong foundation for more advanced programming tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Industry Relevance
&lt;/h2&gt;

&lt;p&gt;Many industries and software development roles require knowledge of typed languages. Learning a typed language as a beginner can open up more job opportunities and career paths in fields such as software engineering, data analysis, and game development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Smooth Transition
&lt;/h2&gt;

&lt;p&gt;Once you've mastered a typed language, transitioning to loosely typed languages becomes more manageable. You'll already have a strong grasp of fundamental programming concepts, making it easier to adapt to different language paradigms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While loosely typed languages have their merits and are often praised for their simplicity, learning a typed language as a beginner can offer numerous advantages. From early error detection to improved code readability and enhanced debugging tools, the structured nature of typed languages can accelerate the learning process and prepare you for a wider range of programming challenges. Whether you choose Java, C++, or another typed language, the skills you acquire will be valuable assets in your journey as a programmer.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Navigating the Toxic Waters of Depression: Staying Afloat and Finding Hope</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Wed, 30 Aug 2023 20:10:23 +0000</pubDate>
      <link>https://forem.com/derekzyl/navigating-the-toxic-waters-of-depression-staying-afloat-and-finding-hope-5h91</link>
      <guid>https://forem.com/derekzyl/navigating-the-toxic-waters-of-depression-staying-afloat-and-finding-hope-5h91</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Depression, often described as a silent storm, has the power to engulf even the most vibrant souls in its deep and murky waters. The toxicity of depression goes beyond its emotional toll; it permeates every aspect of a person's life, casting a shadow that can be suffocating. However, it's essential to remember that even in the darkest of times, there are ways to stay afloat and find hope amidst the waves of despair.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Toxicity of Depression&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Depression is not merely a feeling of sadness; it's a complex and multifaceted mental health condition that affects thoughts, emotions, behaviors, and even physical well-being. Its toxicity lies in the way it distorts perceptions, saps energy, and fosters self-doubt. The negative thoughts and self-criticism that accompany depression can create a cycle of despair, leading to a heightened sense of isolation and hopelessness.&lt;/p&gt;

&lt;p&gt;Moreover, the toxic nature of depression often spills over into relationships. Friends and family members may struggle to comprehend the internal battles a person with depression faces, leading to frustration and miscommunication. This can intensify the feeling of being alone in the struggle, reinforcing the notion that there's no way out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Staying Afloat in the Depths of Depression&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While depression's grip might feel overwhelming, there are ways to combat its toxicity and keep your head above water:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reach Out for Support&lt;/strong&gt;: Remember that you're not alone in this battle. Reach out to friends, family, or mental health professionals who can provide understanding and guidance. Their support can help you navigate the challenging times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seek Professional Help&lt;/strong&gt;: A mental health professional can offer invaluable tools and strategies to manage depression. Therapy, medication, or a combination of both might be necessary to address the underlying issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Practice Self-Compassion&lt;/strong&gt;: Challenge the toxic self-talk by treating yourself with the same kindness you'd offer to a friend. Understand that depression distorts your perception, and your worth isn't defined by it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Realistic Goals&lt;/strong&gt;: Break down tasks into manageable steps to avoid feeling overwhelmed. Celebrate even the smallest achievements, as they represent victories against the grip of depression.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Engage in Physical Activity&lt;/strong&gt;: Exercise has been proven to release endorphins and improve mood. Even a short walk can make a significant difference in how you feel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mindfulness and Meditation&lt;/strong&gt;: These practices can help you stay grounded in the present moment and reduce the overwhelming nature of negative thoughts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creative Outlets&lt;/strong&gt;: Expressing yourself through art, writing, or any creative outlet can provide a healthy way to process emotions and channel them into something positive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Healthy Routine&lt;/strong&gt;: Establish a routine that includes regular sleep patterns, a balanced diet, and activities that bring you joy.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Finding Hope in the Darkness&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's important to acknowledge that finding hope while battling depression can be incredibly challenging, but it's not impossible. Hope often emerges from the journey itself—the moments of strength you discover within yourself, the support you receive, and the gradual progress you make.&lt;/p&gt;

&lt;p&gt;Remember that seeking help isn't a sign of weakness; it's a testament to your courage and determination to overcome the toxicity of depression. By reaching out for support, practicing self-compassion, and engaging in positive activities, you can slowly chip away at the darkness and uncover the glimmers of hope that lie beneath.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Depression's toxicity can be all-encompassing, but it's crucial to understand that it doesn't define who you are. You are not your depression. With the right strategies and support, you can navigate these turbulent waters and find your way to a place of healing and hope. Every step you take towards staying afloat is a step towards reclaiming your life from the clutches of darkness.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>TypeScript and Go: Syntax Comparison and Contrast</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Wed, 09 Aug 2023 21:02:12 +0000</pubDate>
      <link>https://forem.com/derekzyl/typescript-and-go-syntax-comparison-and-contrast-5139</link>
      <guid>https://forem.com/derekzyl/typescript-and-go-syntax-comparison-and-contrast-5139</guid>
      <description>&lt;p&gt;TypeScript and Go are two modern programming languages that have gained popularity for their simplicity, efficiency, and strong type systems. While they serve different purposes and have distinct features, comparing and contrasting their syntax can provide valuable insights into their strengths and use cases. In this article, we'll explore the syntax of TypeScript and Go, highlighting their similarities and differences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Annotations vs. Type Inference
&lt;/h2&gt;

&lt;p&gt;One of the key differences between TypeScript and Go is how they handle type annotations. TypeScript uses static typing with explicit type annotations, allowing developers to specify the types of variables, function parameters, and return values.&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;// TypeScript&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In contrast, Go employs type inference, where the compiler deduces the variable types based on the assigned values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"!"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Null and Undefined
&lt;/h2&gt;

&lt;p&gt;TypeScript distinguishes between &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;, reflecting the semantics of JavaScript.&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;// TypeScript&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go, on the other hand, only has the &lt;code&gt;nil&lt;/code&gt; value to represent the absence of a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Control Flow
&lt;/h2&gt;

&lt;p&gt;Both languages support familiar control flow statements like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, and &lt;code&gt;switch&lt;/code&gt;. However, TypeScript's syntax is influenced by JavaScript, while Go follows a more C-like syntax.&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;// TypeScript&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;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;anotherCondition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;anotherCondition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;Functions in both languages are first-class citizens, but there are syntax differences.&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;// TypeScript&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&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;b&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="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Error Handling
&lt;/h2&gt;

&lt;p&gt;TypeScript uses &lt;code&gt;try&lt;/code&gt;, &lt;code&gt;catch&lt;/code&gt;, and &lt;code&gt;throw&lt;/code&gt; for error handling, similar to JavaScript.&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;// TypeScript&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go employs explicit error handling with returned error values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While TypeScript and Go have distinct syntax styles influenced by their respective programming paradigms, both languages prioritize simplicity, readability, and expressiveness. TypeScript's focus on strong typing and its close relationship with JavaScript make it an excellent choice for frontend and full-stack web development. Go's emphasis on performance, concurrency, and simplicity makes it ideal for backend development and system programming.&lt;/p&gt;

&lt;p&gt;By understanding the syntax similarities and differences between TypeScript and Go, developers can leverage the strengths of each language to build robust and efficient applications tailored to their specific requirements.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Development Journey Pitfalls</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Wed, 19 Jul 2023 20:25:43 +0000</pubDate>
      <link>https://forem.com/derekzyl/development-journey-pitfalls-50l5</link>
      <guid>https://forem.com/derekzyl/development-journey-pitfalls-50l5</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fNA5mNFh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmrktsug8247liafkm9i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fNA5mNFh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmrktsug8247liafkm9i.jpg" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Embarking on a web development journey can be an exciting and rewarding experience. As you dive into the world of coding, design, and user experience, it's important to be aware of the potential pitfalls that lie ahead. Understanding these common challenges can help you navigate your path more efficiently and avoid unnecessary frustrations. In this article, we will explore some of the pitfalls you may encounter during your web development journey and provide tips to overcome them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lack of Planning
&lt;/h2&gt;

&lt;p&gt;One of the biggest mistakes aspiring web developers make is diving into a project without proper planning. Skipping this crucial step can lead to disorganized code, inefficient workflows, and a lack of clarity in your goals. Before starting any web development project, take the time to plan your website's structure, design, and functionality. Create wireframes, flowcharts, and establish a roadmap to guide your development process. Proper planning will save you time and effort in the long run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inadequate Knowledge
&lt;/h2&gt;

&lt;p&gt;Web development is a vast field that requires a solid understanding of various technologies and frameworks. It's easy to get overwhelmed by the sheer amount of information available. Many beginners fall into the trap of trying to learn everything at once, leading to confusion and frustration. Instead, focus on mastering the fundamentals of HTML, CSS, and JavaScript before delving into more complex frameworks. Break your learning into manageable chunks and gradually build upon your knowledge base.&lt;/p&gt;

&lt;h2&gt;
  
  
  Poor Time Management
&lt;/h2&gt;

&lt;p&gt;Web development projects can often take longer than anticipated, especially if you're working on multiple tasks simultaneously. Poor time management can result in missed deadlines, compromised quality, and increased stress levels. To avoid this pitfall, set realistic goals and create a schedule that allocates time for each task. Prioritize your tasks based on their importance and deadline. Additionally, don't forget to take breaks and maintain a healthy work-life balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ignoring Cross-Browser Compatibility
&lt;/h2&gt;

&lt;p&gt;Different web browsers interpret code and display websites in slightly different ways. Neglecting cross-browser compatibility can lead to a website that looks and functions well in one browser but breaks in another. To prevent this, test your website across multiple browsers (such as Chrome, Firefox, Safari, and Edge) to ensure consistent performance. Utilize tools and techniques to identify and fix compatibility issues, such as using vendor prefixes and following web standards.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limited User Testing
&lt;/h2&gt;

&lt;p&gt;User experience (UX) is a crucial aspect of web development. Without proper user testing, you risk delivering a website that fails to meet the needs and expectations of your target audience. Don't solely rely on your own judgment when evaluating your website's usability. Encourage friends, colleagues, or potential users to test your site and provide feedback. Conduct usability tests, gather data, and iterate based on user insights. This iterative process will help you create a user-friendly and intuitive website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Embarking on a web development journey can be challenging, but with awareness and preparation, you can overcome the common pitfalls that arise along the way. By embracing proper planning, continuous learning, effective time management, cross-browser compatibility, and user testing, you'll be well-equipped to navigate your path to becoming a proficient web developer. Remember, persistence, patience, and a willingness to learn from your mistakes will ultimately lead you to success in the ever-evolving world of web development.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React vs svelte vs angular vs vanilla js vs vue</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Wed, 15 Feb 2023 20:32:50 +0000</pubDate>
      <link>https://forem.com/derekzyl/react-vs-svelte-vs-angular-vs-vanilla-js-vs-vue-2n9a</link>
      <guid>https://forem.com/derekzyl/react-vs-svelte-vs-angular-vs-vanilla-js-vs-vue-2n9a</guid>
      <description>&lt;p&gt;React, Svelte, Vue, VanillaJS, and Angular are all popular front-end JavaScript frameworks and libraries used for building dynamic and interactive web applications. Here's a brief overview of each one with a 'hello world' example:&lt;/p&gt;

&lt;p&gt;React: Developed by Facebook, React is a widely adopted JavaScript library for building user interfaces. It's a component-based library that allows you to easily manage and update the state of your UI, making it a popular choice for large-scale, complex applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Svelte: Svelte is a new and emerging framework that is gaining popularity in the JavaScript community. It is a compiler-based framework that compiles the code at build time, which allows for smaller bundle sizes and faster performance. Svelte is also known for its simplicity, ease of use, and the ability to write less code to achieve the same functionality compared to other frameworks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let name = 'World';
&amp;lt;/script&amp;gt;

&amp;lt;h1&amp;gt;Hello {name}!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vue: Vue is a progressive JavaScript framework that is designed to be easy to use and flexible. It's known for its ease of integration with existing projects and the ability to scale up or down depending on the size of the project. Vue also provides a wide range of features out-of-the-box, including a state management system and component-based architecture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Hello {{ name }}!&amp;lt;/h1&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
  name: 'App',
  data() {
    return {
      name: 'World'
    }
  }
}
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;VanillaJS: VanillaJS, also known as plain JavaScript, is the native JavaScript language without the use of any libraries or frameworks. While it requires more coding than the other frameworks, VanillaJS is a great option for small projects, and it can also be used alongside other frameworks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1 id="myHeading"&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
    &amp;lt;script&amp;gt;
      document.getElementById('myHeading').textContent = 'Hello World!';
    &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Angular: Developed by Google, Angular is a comprehensive framework that provides a full set of features for building complex web applications. It's known for its strong opinionated structure, dependency injection system, and advanced features like two-way data binding and powerful directives.&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;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&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="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;h1&amp;gt;Hello {{ name }}!&amp;lt;/h1&amp;gt;&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;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;World&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, the choice between these frameworks ultimately depends on the project's specific requirements, developer preferences, and the team's expertise. All these frameworks have their strengths and weaknesses, and it's essential to consider them while choosing a framework for a particular project.&lt;/p&gt;

</description>
      <category>tooling</category>
      <category>productivity</category>
      <category>discuss</category>
    </item>
    <item>
      <title>A Developers Sad Story</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Wed, 21 Dec 2022 21:25:12 +0000</pubDate>
      <link>https://forem.com/derekzyl/a-developers-sad-story-1368</link>
      <guid>https://forem.com/derekzyl/a-developers-sad-story-1368</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;everything all started like a pick of interest as i wondered how these apps and websites were being developed, it all seemed like magic and there was no how i could get a hold of learning how to write codes. The first developer i met Alex was typically astounding as he could literally develop websites and he ha done several jobs. This got me excited which was clearly short lived because i got to realize he was using wordpress and Jomla for his web development; and i was sure it wasn't what i needed. I then picked some online books and PDF and kick start the journey. At first they were looking all abstract as i didn't where to even start from. I dangled into some on the surface idea for a while and had to drop the idea of learning after a while of not getting ahold of what i needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Body
&lt;/h3&gt;

&lt;p&gt;The little i learned made me look like a tech savvy as i knew how to talk tech and these gave a lot of folks and foes the impression that i was a developer. I had severally picked interest and started again but got discouraged because i needed to work to get food on the table. It was hell at that period cause i wanted to learn at the same time i was responsible for I and someone else. What broke the camels back was my laptop got bad because of my roommate in the halls of residence in school mal-handled the pc. I couldn't afford a PC for over a year cause my earnings wasn't sufficient to save to get a new pc.I attempted using my phone to learn but it was still hell as no one was available to guide me I then one way or the other managed to get at least a pc that was working fine. Immediately i started learning graphics design with it (Adobe illustrator, Adobe PhotoShop, and Adobe XD) these three i got deep into and i started getting small jobs on logo designs and flyers.&lt;/p&gt;

&lt;p&gt;I then resumed learning programming and javascript was still abstract as i did not understand the concept of how javascript communicated with the DOM; I immediately stumbled into React as a friend asked me if i knew any thing about it. React was awesome it was straight forward i didn't need to talk to the DOM directly. I the started watching series of tutorial videos many wasn't making sense and most times i just rewrite what i learnt i realized i wasn't getting it fully; i then stumbled upon Django and it was still awesome as everything was straight forward. i got some jobs for clients and these projects worked well.&lt;/p&gt;

&lt;h3&gt;
  
  
  conclusion
&lt;/h3&gt;

&lt;p&gt;I knew i was still lacking skills and video tutorials weren't working at all cause for three months again i was learning frameworks(Django, React). I then met a friend that changed my life forever he recommended some things i do and i added some twist also that might help some persons out there:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;please you need to learn the programming language before you move to the framework&lt;/li&gt;
&lt;li&gt;you need to read official documentations&lt;/li&gt;
&lt;li&gt;if you can avoid tutorial videos especially project videos but you can use tutorial videos to learn a language or documentation&lt;/li&gt;
&lt;li&gt;join active communities&lt;/li&gt;
&lt;li&gt;do hackathons, leetcodes etc&lt;/li&gt;
&lt;li&gt;preference books over videos&lt;/li&gt;
&lt;li&gt;use github every time&lt;/li&gt;
&lt;li&gt;start making noise even when you have learnt a bite of tech it will create awareness to your employers so that when you are ready a spacemight be available for you&lt;/li&gt;
&lt;li&gt;make your little experience make a louder noise on twitter, linkedin, github, and others&lt;/li&gt;
&lt;li&gt;know this i the beginning "tech is hard" but there persons that know it don't got two heads&lt;/li&gt;
&lt;li&gt;use tutorial videos to learn project flows and you don't need to code along having this in mind that you are familiar with all or most of the tools the project will implement&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>writing</category>
    </item>
    <item>
      <title>django referral app and allauth</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Fri, 24 Sep 2021 21:40:48 +0000</pubDate>
      <link>https://forem.com/derekzyl/django-referral-app-and-allauth-4d31</link>
      <guid>https://forem.com/derekzyl/django-referral-app-and-allauth-4d31</guid>
      <description>&lt;p&gt;with current tech of referral being a strategy to boost businesses both offline and online I've chosen to write some codes on how to create referral links with Django-allauth and django sessions. &lt;br&gt;
inspiration of the referral was gotten from a youtube video of pyplane .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import uuid

def generate_ref_code():
    code =str(uuid.uuid4()).replace('-', '')[:12]
    return code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;models&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from django.db import models

# Create your models here.
from core.models import TheMain
from referral.utils import generate_ref_code
from user.models import User


class Referral(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    referral_balance = models.IntegerField(default=0)
    code = models.CharField(max_length=12, blank=True)
    referred_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, related_name="ref_by")
    updated = models.DateTimeField(auto_now=True)
    created = models.DateTimeField(auto_now_add=True)
    approve= models.BooleanField(default=False)

    def __str__(self):
        return f'{self.user.username}- {self.code}'

    def get_reffered(self):
        qs = Referral.objects.all()
        my_refs = []
        for reffered in qs:
            if reffered.referred_by == self.user:
                my_refs.append(reffered)
        return my_refs



    def save(self, *args, **kwargs):
        if self.code == '':
            code = generate_ref_code()
            self.code = code
        super().save(*args, **kwargs)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the user referral id  is automatically generated with UUID&lt;/p&gt;

&lt;p&gt;the extended all-auth &lt;strong&gt;form view&lt;/strong&gt; I guess I don't need to tell you about djangoallauth.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class mySignUp(SignupForm):
    first_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={
        'placeholder': 'First name'
    }))
    last_name = forms.CharField(max_length=50, widget=forms.TextInput(attrs={
        'placeholder': 'Last name'
    }))
    country = CountryField(blank_label='select country').formfield(widget=CountrySelectWidget(attrs={
        'class': 'custom-select d-block w-100'
    }))
    phone = forms.IntegerField(required=True, widget=forms.TextInput(attrs={
        'placeholder': 'Phone number'
    }))

    # def save(self,  request):
    #     user = super(mySignUp, self).save(request)
    #
    #     user.first_name = self.cleaned_data['first_name']
    #     user.last_name = self.cleaned_data['last_name']
    #     user.country = self.cleaned_data['country']
    #     user.phone = self.cleaned_data['phone']
    #     user.save()
    #     print(f'this is the user {user}')
    #     return user

    def save(self, request):
        referral_id = request.session.get('ref_profile')
        print(f'this is login{referral_id}')
        if referral_id is not None:
            recommended_by_profile = Referral.objects.get(id=referral_id)
            user = super(mySignUp, self).save(request)

            user.first_name = self.cleaned_data['first_name']
            user.last_name = self.cleaned_data['last_name']
            user.country = self.cleaned_data['country']
            user.phone = self.cleaned_data['phone']
            user.save()

            registered_user = User.objects.get(id=user.id)
            registered_profile = Referral.objects.get(user=registered_user)
            registered_profile.referred_by = recommended_by_profile.user
            registered_profile.save()
            print(f'this is the user {user}')
            print(f'this is the the {user.id}')
            # here after saving the registration I pass the ref id param to the user profile then I save the user 
            profile

            return user
        else:

            user = super(mySignUp, self).save(request)

            user.first_name = self.cleaned_data['first_name']
            user.last_name = self.cleaned_data['last_name']
            user.country = self.cleaned_data['country']
            user.phone = self.cleaned_data['phone']
            user.save()
            print(f'this is the user {user}')
            return user

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def referred(request, *args, **kwargs):
    code = str(kwargs.get('ref_code'))
    print(f'coded code {code}')
    try:
        referral = Referral.objects.get(code=code)
        request.session['ref_profile'] = referral.id
        print('id', referral.id)
    except:
        pass
    print(request.session.get_expiry_age())
    return render(request, 'homepage/index.html', {})



# now in my views I fetch the referred users






from allauth.account.views import SignupView
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.shortcuts import render, get_object_or_404

# Create your views here.
from core.models import TheMain, Invest, TheRef
from referral.models import Referral


@login_required
def referral_page(request, *args, **kwargs):
    global invest_user, invest_name, invest_amount, invest_timer, main, that, ma, new_invest, new_main
    referral = get_object_or_404(Referral, user=request.user)
    my_ref = referral.get_reffered()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;contact me if you need more explanation to this&lt;/p&gt;

&lt;p&gt;reference&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=QZfflGvRQrc"&gt;https://www.youtube.com/watch?v=QZfflGvRQrc&lt;/a&gt;&lt;br&gt;
 by pyplane&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
      <category>developer</category>
    </item>
    <item>
      <title>My Intern Journey At Zuri HNG</title>
      <dc:creator>derekzyl</dc:creator>
      <pubDate>Tue, 17 Aug 2021 13:10:09 +0000</pubDate>
      <link>https://forem.com/derekzyl/my-intern-journey-at-zuri-hng-387</link>
      <guid>https://forem.com/derekzyl/my-intern-journey-at-zuri-hng-387</guid>
      <description>&lt;p&gt;This article is about my first tech stack internship. I've been quite curious about how to make industry-standard in coding, collaborating with individuals, and making a target come through with a said given time well all these always plays perfectly well in my simulation but there are too many variables that are not accounted for when it comes to just think things in the head.&lt;br&gt;
Then a friend sent me a link to register for an internship programme at ZURI. Well, currently it is quite fun meeting quite some developers and an admin @naza that is quite cool and fun though. I would recommend you visit &lt;a href="https://zuri.team"&gt;https://zuri.team&lt;/a&gt; to see what these guys do out there. If you want to dive into an internship right away, I strongly recommend &lt;a href="https://interns.zuri.team"&gt;https://interns.zuri.team&lt;/a&gt;. I know what you'll be thinking currently that this article might just be for persons that are already into programming well you could start your tech journey at &lt;a href="https://training.zuri.team"&gt;https://training.zuri.team&lt;/a&gt;. &lt;br&gt;
At the commencement of my intern journey I've written out some goals I'll want to achieve at the end of the internship these are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;profound knowledge on how the tech firms/companies operate&lt;/li&gt;
&lt;li&gt;work with individuals to achieve a task or goal, etc&lt;/li&gt;
&lt;li&gt;well equipped for the tech space with necessary information&lt;/li&gt;
&lt;li&gt;cover lapses in my mobile development tech stack 
well I still got to name what ill love to achieve in the coming weeks for the internship&lt;/li&gt;
&lt;li&gt;get a better relationship with working and partnering with developers&lt;/li&gt;
&lt;li&gt;know how to work with teams&lt;/li&gt;
&lt;li&gt;become a god or maybe a Demi-god in mobile app development. ie Zeus mode&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'll be dropping some links to some tutorial videos in various tech stacks ill employ you to check them out; you know what they say the journey of a thousand miles starts with a step.&lt;br&gt;
let us start with:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;UI/UX:
It's majorly for prototyping and designs to follow this tutorial to proceed and get to know more about it-&lt;a href="https://www.youtube.com/watch?v=jk1T0CdLxwU"&gt;https://www.youtube.com/watch?v=jk1T0CdLxwU&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GIT:
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency (source- &lt;a href="https://git.com"&gt;https://git.com&lt;/a&gt;) well if you want to know more about git follow this tutorial link- &lt;a href="https://www.youtube.com/watch?v=8JJ101D3knE"&gt;https://www.youtube.com/watch?v=8JJ101D3knE&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;HTML:
HTML is the standard markup language for creating Web pages (source- &lt;a href="https://www.w3schools.com/html/html_intro.asp"&gt;https://www.w3schools.com/html/html_intro.asp&lt;/a&gt;). now the tutorial if you like reading books I will recommend &lt;a href="https://html.com/"&gt;https://html.com/&lt;/a&gt; and  videos &lt;a href="https://www.youtube.com/watch?v=qz0aGYrrlhU"&gt;https://www.youtube.com/watch?v=qz0aGYrrlhU&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;flutter:
Flutter is an open-source framework to create high quality, high-performance mobile applications across mobile operating systems - Android and iOS. It provides a simple, powerful, efficient and easy to understand SDK to write mobile applications in Google's language, Dart. This tutorial walks through the basics of Flutter framework, installation of Flutter SDK, setting up Android Studio to develop Flutter based application, the architecture of Flutter framework and developing all types of mobile applications using Flutter framework (source- &lt;a href="https://www.tutorialspoint.com/flutter/index.htm"&gt;https://www.tutorialspoint.com/flutter/index.htm&lt;/a&gt;) beginner tutorial videos to flutter &lt;a href="https://www.youtube.com/watch?v=1ukSR1GRtMU"&gt;https://www.youtube.com/watch?v=1ukSR1GRtMU&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Dart:
A programming language optimized for building user interfaces with features such as sound null safety, the spread operator for expanding collections, and collection if for customizing UI for each platform( source- &lt;a href="https://dart.dev/"&gt;https://dart.dev/&lt;/a&gt;) follow this link to start asap with dart &lt;a href="https://www.youtube.com/watch?v=Ej_Pcr4uC2Q"&gt;https://www.youtube.com/watch?v=Ej_Pcr4uC2Q&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
