<?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: Nitin Malviya</title>
    <description>The latest articles on DEV Community by Nitin Malviya (@nitinmalviy).</description>
    <link>https://dev.to/nitinmalviy</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%2F3584160%2F4548cc02-041a-4c6b-92bd-fe73a42db50e.png</url>
      <title>DEV Community: Nitin Malviya</title>
      <link>https://dev.to/nitinmalviy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nitinmalviy"/>
    <language>en</language>
    <item>
      <title>How Kafka Saved a Failing System -The Story of Arjun &amp; Meera</title>
      <dc:creator>Nitin Malviya</dc:creator>
      <pubDate>Mon, 24 Aug 2026 14:04:56 +0000</pubDate>
      <link>https://dev.to/nitinmalviy/how-kafka-saved-a-failing-system-the-story-of-arjun-meera-4ogd</link>
      <guid>https://dev.to/nitinmalviy/how-kafka-saved-a-failing-system-the-story-of-arjun-meera-4ogd</guid>
      <description>&lt;p&gt;Modern systems run on data in the form of fast, real-time, continuous streams.&lt;/p&gt;

&lt;p&gt;But what happens when your system grows faster than your architecture can handle?&lt;/p&gt;

&lt;p&gt;This is the story of &lt;strong&gt;Arjun&lt;/strong&gt;, a backend engineer from Indore, and &lt;strong&gt;Meera&lt;/strong&gt;, a DevOps engineer — and how &lt;strong&gt;Kafka&lt;/strong&gt; rescued their collapsing system while teaching them how real-time streaming actually works.&lt;/p&gt;

&lt;p&gt;It's a story, but it's also a complete walkthrough: why queues break, what Kafka replaces them with, the code, the bugs, and the cases where Kafka is genuinely the wrong choice.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 1: The Breaking Point
&lt;/h2&gt;

&lt;p&gt;SwiftKart, a fast-growing hyperlocal delivery startup, was booming.&lt;/p&gt;

&lt;p&gt;Orders jumped from &lt;strong&gt;4,000 to 40,000 per day&lt;/strong&gt; in just two months.&lt;/p&gt;

&lt;p&gt;But growth brought chaos. Arjun, the Node.js backend engineer, was drowning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Notifications delayed by 15 minutes&lt;/li&gt;
&lt;li&gt;Redis queue overflowing&lt;/li&gt;
&lt;li&gt;Analytics dashboard freezing&lt;/li&gt;
&lt;li&gt;Duplicate messages&lt;/li&gt;
&lt;li&gt;Missing events&lt;/li&gt;
&lt;li&gt;Workers crashing randomly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Meanwhile, Meera's monitoring showed red spikes everywhere.&lt;/p&gt;

&lt;p&gt;Arjun said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Meera, the system can't breathe. The Redis queue is suffocating!"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Their stack was the classic startup design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js microservices&lt;/li&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;Redis job queues&lt;/li&gt;
&lt;li&gt;Background workers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Perfect at small scale. Completely helpless for &lt;strong&gt;high-volume real-time streaming&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 2: Why Their Old System Failed
&lt;/h2&gt;

&lt;p&gt;As traffic increased, the cracks became craters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Queue overflow.&lt;/strong&gt; Redis had a single-lane queue → bottlenecks everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. No durability.&lt;/strong&gt; If Redis restarts, messages disappear.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. No replay.&lt;/strong&gt; Consumed once = gone forever. If analytics breaks, that data is lost permanently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Slow consumers collapsed the system.&lt;/strong&gt; Events arrived faster than workers could drain them, and back-pressure took everything down with it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. No multi-consumer support.&lt;/strong&gt; Analytics, notifications, fraud detection — sabko same event chahiye tha. Redis sirf ek consumer ko deta tha. Baaki sab bhookhe.&lt;/p&gt;

&lt;p&gt;Arjun finally said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"We need a real streaming system. Not this jugaad."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Chapter 3: The Monday Meeting — Kafka Enters
&lt;/h2&gt;

&lt;p&gt;The CTO walked into the meeting room and declared:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"We are moving to Kafka."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Arjun frowned. &lt;em&gt;"Isn't Kafka too complex? Why do we need it?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Meera smiled. &lt;em&gt;"Kafka isn't overkill. It's exactly what we need."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Kafka gives you:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pro&lt;/th&gt;
&lt;th&gt;What it means in practice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;High throughput&lt;/td&gt;
&lt;td&gt;Millions of events/sec on modest hardware&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Durability&lt;/td&gt;
&lt;td&gt;Events written to disk and replicated — a broker dying loses nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scalability&lt;/td&gt;
&lt;td&gt;Add partitions and consumers instead of rewriting the system&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replay&lt;/td&gt;
&lt;td&gt;Reset an offset and reprocess history&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fault tolerance&lt;/td&gt;
&lt;td&gt;Replicas take over automatically&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decoupled architecture&lt;/td&gt;
&lt;td&gt;Producers don't know or care who consumes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;And the cons, honestly:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Complex to operate&lt;/li&gt;
&lt;li&gt;Resource-heavy&lt;/li&gt;
&lt;li&gt;Genuine overkill for small apps&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But SwiftKart had moved well beyond "small."&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 4: Kafka Explained Like Arjun Understood It
&lt;/h2&gt;

&lt;p&gt;Meera drew a diagram on the whiteboard and started with the sentence that reframed everything:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Kafka is not a queue. Kafka is a distributed, durable, replayable event log.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A queue deletes a message when someone reads it. A log doesn't. Readers just move a bookmark forward, and every reader has their own bookmark.&lt;/p&gt;

&lt;p&gt;Then the vocabulary:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;What it is&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Topic&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A category of events, e.g. &lt;code&gt;order.events&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Partition&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Parallel lanes inside a topic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Offset&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A message's index within a partition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Producer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A service that sends events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consumer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A service that reads events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Consumer group&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A team of consumers sharing the load of one topic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Broker&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A Kafka server that stores data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cluster&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A collection of brokers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Replication&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Copies of data across brokers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Retention&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;How long data stays before deletion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The one that took Arjun longest: &lt;strong&gt;consumer group&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consumers &lt;em&gt;in the same group&lt;/em&gt; split partitions between them — that's how you scale. Consumers in &lt;em&gt;different groups&lt;/em&gt; each get their own copy of every message — that's how notifications, analytics and fraud detection all read the same event stream without fighting over it.&lt;/p&gt;

&lt;p&gt;That single distinction is what Redis could never do.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 5: The Migration Plan — Nobody Turns Redis Off on a Friday
&lt;/h2&gt;

&lt;p&gt;Arjun's first instinct was to rip out Redis in one weekend.&lt;/p&gt;

&lt;p&gt;Meera stopped him.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Agar tumne ek hi raat mein switch kiya, aur Kafka mein koi bug nikla, toh 40,000 orders ka data kahan jayega? Migration is not a deploy. It's a slow, boring, reversible process."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They agreed on a three-week plan.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 1 — Dual write.&lt;/strong&gt; Every service that pushed to Redis now also published the same event to Kafka. Redis stayed the source of truth; Kafka just quietly collected events. Zero risk — if Kafka broke, nothing broke.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 2 — Shadow consumers.&lt;/strong&gt; New Kafka consumers ran alongside the old Redis workers, doing the same work but writing to a separate analytics table. Every morning Meera compared both tables. When the counts matched for seven days straight, they had proof.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 3 — Cutover, one consumer at a time.&lt;/strong&gt; Notifications first (least damage if it broke). Analytics second. Fraud detection last. The Redis workers were disabled, not deleted, for another two weeks.&lt;/p&gt;

&lt;p&gt;Then came the part Arjun underestimated: &lt;strong&gt;designing the topics.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;His first draft had one topic called &lt;code&gt;events&lt;/code&gt;. Meera rejected it immediately.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"One topic for everything means one retention policy for everything, one partition count for everything, and no way to give a team access to only what it needs."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The final design:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;th&gt;Partitions&lt;/th&gt;
&lt;th&gt;Retention&lt;/th&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;order.events&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;7 days&lt;/td&gt;
&lt;td&gt;&lt;code&gt;orderId&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;payment.events&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;30 days&lt;/td&gt;
&lt;td&gt;&lt;code&gt;orderId&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;notification.requests&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;1 day&lt;/td&gt;
&lt;td&gt;&lt;code&gt;userId&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;order.events.dlq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;30 days&lt;/td&gt;
&lt;td&gt;&lt;code&gt;orderId&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two rules drove every choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The key decides the order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kafka guarantees ordering &lt;em&gt;inside a partition&lt;/em&gt;, not across a topic. Keying by &lt;code&gt;orderId&lt;/code&gt; means every event for order #5512 — &lt;code&gt;CREATED&lt;/code&gt;, &lt;code&gt;PACKED&lt;/code&gt;, &lt;code&gt;PICKED_UP&lt;/code&gt;, &lt;code&gt;DELIVERED&lt;/code&gt; — lands in the same partition and is read in sequence. Key it by something random and you will eventually deliver an order before you accept it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Partition count is your maximum parallelism.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A consumer group can never have more active consumers than partitions. 12 partitions = up to 12 notification workers, and the 13th sits idle. You can add partitions later, but adding them &lt;strong&gt;rehashes the keys&lt;/strong&gt;, so old and new events for the same order can land in different partitions. Over-provision a little on day one.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 6: The Code Arjun Actually Wrote
&lt;/h2&gt;

&lt;p&gt;They used &lt;strong&gt;KafkaJS&lt;/strong&gt;, since the whole backend was Node.js.&lt;/p&gt;

&lt;h3&gt;
  
  
  The event envelope
&lt;/h3&gt;

&lt;p&gt;Before writing a single producer, Meera made him standardise the shape of every event:&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;// events/envelope.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;randomUUID&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="s2"&gt;crypto&lt;/span&gt;&lt;span class="dl"&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;function&lt;/span&gt; &lt;span class="nf"&gt;buildEvent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="o"&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;orderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;payload&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;eventId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;randomUUID&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;   &lt;span class="c1"&gt;// for consumer-side deduplication&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                    &lt;span class="c1"&gt;// "ORDER_CREATED"&lt;/span&gt;
    &lt;span class="nx"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                 &lt;span class="c1"&gt;// schema version — you WILL need this&lt;/span&gt;
    &lt;span class="nx"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;occurredAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;payload&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;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Version field abhi useless lagta hai,"&lt;/em&gt; she said. &lt;em&gt;"Six months baad jab tum payload change karoge aur purane consumers crash honge, tab samajh aayega."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The producer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// kafka/producer.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Kafka&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Partitioners&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CompressionTypes&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="s2"&gt;kafkajs&lt;/span&gt;&lt;span class="dl"&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;kafka&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;Kafka&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;order-service&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;brokers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&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;KAFKA_BROKERS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;ssl&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="na"&gt;sasl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;mechanism&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scram-sha-512&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&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;KAFKA_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&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;KAFKA_PASS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;retries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;initialRetryTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&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;producer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;idempotent&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="c1"&gt;// no duplicates on internal retries&lt;/span&gt;
  &lt;span class="na"&gt;maxInFlightRequests&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;createPartitioner&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Partitioners&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DefaultPartitioner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;producer&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;publishOrderEvent&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;order.events&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;acks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                    &lt;span class="c1"&gt;// wait for all in-sync replicas&lt;/span&gt;
    &lt;span class="na"&gt;compression&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CompressionTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GZIP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;messages&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="na"&gt;key&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;orderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// ← this is what guarantees ordering&lt;/span&gt;
        &lt;span class="na"&gt;value&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="nx"&gt;event&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="na"&gt;eventType&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="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&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;version&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="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;Three lines do the heavy lifting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;idempotent: true&lt;/code&gt;&lt;/strong&gt; — when the producer retries after a network blip, the broker recognises the duplicate and drops it. Without this, retries create duplicate events.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;acks: -1&lt;/code&gt;&lt;/strong&gt; — the send only succeeds once every in-sync replica has the message. &lt;code&gt;acks: 1&lt;/code&gt; is faster and loses data when a leader dies mid-write.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;key: event.orderId&lt;/code&gt;&lt;/strong&gt; — ordering, as above. Omit it and Kafka round-robins your events across partitions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The consumer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// consumers/notification.consumer.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;consumer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;groupId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;notification-service&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// each service = its own group&lt;/span&gt;
  &lt;span class="na"&gt;sessionTimeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;heartbeatInterval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;consumer&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="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;order.events&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fromBeginning&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;autoCommit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                &lt;span class="c1"&gt;// commit only after real success&lt;/span&gt;
  &lt;span class="na"&gt;eachMessage&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="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;partition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;heartbeat&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;event&lt;/span&gt; &lt;span class="o"&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;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nextOffset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;n&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="k"&gt;try&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;alreadyProcessed&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;eventId&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="c1"&gt;// dedupe&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendNotification&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;markProcessed&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;eventId&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="nx"&gt;err&lt;/span&gt;&lt;span class="p"&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;sendToDLQ&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;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// park it, don't block the partition&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commitOffsets&lt;/span&gt;&lt;span class="p"&gt;([{&lt;/span&gt; &lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;partition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;nextOffset&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;heartbeat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;              &lt;span class="c1"&gt;// long jobs: prove you're still alive&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SIGTERM&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;      &lt;span class="c1"&gt;// commit in-flight work, leave the group cleanly&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details worth pausing on. You commit the &lt;strong&gt;next&lt;/strong&gt; offset to read, not the one you just processed — hence the &lt;code&gt;+ 1&lt;/code&gt;. And offsets are int64, which is why KafkaJS hands them to you as strings; &lt;code&gt;BigInt&lt;/code&gt; keeps that safe once your topics get busy.&lt;/p&gt;

&lt;p&gt;And here's the part that made Arjun finally &lt;em&gt;get&lt;/em&gt; it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notifications, analytics and fraud each ran the same subscribe call — same topic, different &lt;code&gt;groupId&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All three received every single event, independently, at their own pace. Analytics could be an hour behind and notifications wouldn't care. Redis could never do this. That was the whole point.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 7: The Four Bugs Nobody Warns You About
&lt;/h2&gt;

&lt;p&gt;Kafka went live. Then Kafka started teaching.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 1 — Duplicates came back anyway
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Meera, maine idempotent producer lagaya tha. Phir bhi ek user ko do SMS gaye!"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Producer idempotence only prevents duplicates &lt;strong&gt;on the write side&lt;/strong&gt;. On the read side Kafka is &lt;strong&gt;at-least-once&lt;/strong&gt;: if a consumer processes a message and dies before committing the offset, the next consumer reads it again.&lt;/p&gt;

&lt;p&gt;The fix isn't in Kafka — it's in your consumer. Give every event a unique &lt;code&gt;eventId&lt;/code&gt;, store processed IDs behind a unique constraint, and skip anything you've seen. That's the &lt;code&gt;alreadyProcessed()&lt;/code&gt; call above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assume every message will arrive twice. Design for it.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 2 — The rebalancing death spiral
&lt;/h3&gt;

&lt;p&gt;One notification took 45 seconds (a slow third-party SMS gateway). &lt;code&gt;sessionTimeout&lt;/code&gt; was 30 seconds. Kafka assumed the consumer was dead, evicted it, and triggered a rebalance. The rebalance paused every other consumer. Those consumers then timed out too.&lt;/p&gt;

&lt;p&gt;Three fixes, in order of preference: call &lt;code&gt;heartbeat()&lt;/code&gt; during long work, move the slow call off the consumer path entirely, or raise &lt;code&gt;sessionTimeout&lt;/code&gt; as a last resort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A consumer that goes quiet is a consumer Kafka will evict.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 3 — One bad message froze an entire partition
&lt;/h3&gt;

&lt;p&gt;A malformed payload threw on every retry. Kafka doesn't skip it — it can't, because skipping would break ordering. So the consumer retried forever and every message behind it waited.&lt;/p&gt;

&lt;p&gt;That's what &lt;code&gt;order.events.dlq&lt;/code&gt; is for: catch, park the poison message in a dead-letter topic with the error attached, commit the offset, move on. Fix it offline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Without a DLQ, one bad record can stall a partition indefinitely.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bug 4 — Consumer lag was invisible until it wasn't
&lt;/h3&gt;

&lt;p&gt;Meera added lag monitoring on day three:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kafka-consumer-groups.sh &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; &lt;span class="nv"&gt;$BROKER&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--describe&lt;/span&gt; &lt;span class="nt"&gt;--group&lt;/span&gt; notification-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;LAG&lt;/code&gt; column is the single most important number in a Kafka system — it tells you how far behind reality your consumers are. They alerted at lag &amp;gt; 10,000 and scaled consumers (never beyond the partition count) when it fired.&lt;/p&gt;

&lt;h3&gt;
  
  
  And the security bits Arjun almost shipped without
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The brokers were exposed with &lt;code&gt;PLAINTEXT&lt;/code&gt; initially. They moved to &lt;strong&gt;SASL/SCRAM over TLS&lt;/strong&gt; — the config in the producer above.&lt;/li&gt;
&lt;li&gt;Every service got its &lt;strong&gt;own credentials and ACLs&lt;/strong&gt;. The notification service can read &lt;code&gt;order.events&lt;/code&gt; and nothing else; it has no business writing to &lt;code&gt;payment.events&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No raw PII in event payloads.&lt;/strong&gt; Kafka retains data for days and every consumer group reads everything. Send &lt;code&gt;userId&lt;/code&gt; and let the consumer look up the phone number. A topic is not a place to store card numbers.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Chapter 8: Two Months Later
&lt;/h2&gt;

&lt;p&gt;Arjun opened the dashboard on a Monday morning. Orders had crossed 90,000/day.&lt;/p&gt;

&lt;p&gt;Nothing was on fire.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Before (Redis queue)&lt;/th&gt;
&lt;th&gt;After (Kafka)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Notification delay&lt;/td&gt;
&lt;td&gt;up to 15 min&lt;/td&gt;
&lt;td&gt;under 2 sec&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Peak throughput&lt;/td&gt;
&lt;td&gt;~1,200 events/min&lt;/td&gt;
&lt;td&gt;40,000+ events/min&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Broker restart&lt;/td&gt;
&lt;td&gt;messages lost&lt;/td&gt;
&lt;td&gt;messages survive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replay after a bug&lt;/td&gt;
&lt;td&gt;impossible&lt;/td&gt;
&lt;td&gt;reset offset, reprocess&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Consumers per event&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;unlimited groups&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slow consumer&lt;/td&gt;
&lt;td&gt;took down the system&lt;/td&gt;
&lt;td&gt;falls behind, alone&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The moment that convinced the CTO wasn't the throughput number.&lt;/p&gt;

&lt;p&gt;Analytics had a bug for six days — a wrong tax calculation on every order. Under Redis, that data was consumed and gone; six days of reporting would have been permanently wrong. With Kafka, Meera reset the analytics consumer group's offset to a week earlier and reprocessed everything in forty minutes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Kafka isn't just faster,"&lt;/em&gt; she said. &lt;em&gt;"It gave you a time machine for your data."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  But please don't copy this blindly
&lt;/h3&gt;

&lt;p&gt;Kafka is the wrong answer for a lot of teams, and Arjun is very clear about that now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Under ~10,000 events/day?&lt;/strong&gt; Redis, BullMQ or a database-backed queue will serve you better at a fraction of the operational effort.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Need per-message delay, priority or scheduling?&lt;/strong&gt; That's a job queue's job. Kafka has no concept of "run this one first" or "run this in 10 minutes."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nobody to own it?&lt;/strong&gt; Kafka isn't a library you install, it's infrastructure someone maintains — partitions, retention, rebalances, lag, upgrades. (Modern Kafka runs on KRaft, so at least ZooKeeper is no longer part of the deal.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One consumer and no replay requirement?&lt;/strong&gt; Then you're paying Kafka's complexity tax for features you don't use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Kafka solved SwiftKart's problem because SwiftKart had exactly the problem Kafka is built for: &lt;strong&gt;high volume, multiple independent consumers, and a hard need for durability and replay.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If that's not your problem, it's not your tool.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you're running Kafka in production, I'd love to hear how you sized your partitions — it's the one decision that's genuinely hard to undo.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>systemdesign</category>
      <category>distributedsystems</category>
      <category>backend</category>
    </item>
    <item>
      <title>JS + DSA Roadmap (3–4 Months)</title>
      <dc:creator>Nitin Malviya</dc:creator>
      <pubDate>Mon, 27 Oct 2025 06:50:58 +0000</pubDate>
      <link>https://dev.to/nitinmalviy/js-dsa-roadmap-3-4-months-4c1</link>
      <guid>https://dev.to/nitinmalviy/js-dsa-roadmap-3-4-months-4c1</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Month 1: Foundation &amp;amp; Recursion&lt;/strong&gt;
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;Recursion basics (factorial, Fibonacci, sum of array, reverse string, power of number)&lt;/li&gt;
&lt;li&gt;Time &amp;amp; Space Complexity basics (O(1), O(n), O(n²), O(log n))&lt;/li&gt;
&lt;li&gt;Iterative vs Recursive solutions comparison&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Solve &lt;strong&gt;10–12 recursion problems&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Analyze &lt;strong&gt;TC &amp;amp; SC&lt;/strong&gt; for each&lt;/li&gt;
&lt;li&gt;Dry run + recursion stack understanding&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Month 2: Arrays &amp;amp; Linked Lists&lt;/strong&gt;
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;Arrays (search, sort, sliding window, two pointers)&lt;/li&gt;
&lt;li&gt;Linked List: Single, Doubly, Circular&lt;/li&gt;
&lt;li&gt;Operations: Insert, Delete, Reverse, Merge, Detect Loop&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;5 problems per topic (Array + Linked List)&lt;/li&gt;
&lt;li&gt;TC/SC analysis for each solution&lt;/li&gt;
&lt;li&gt;Pattern recognition (sliding window, fast/slow pointers)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Month 3: Stack, Queue, Hash Table, Trees&lt;/strong&gt;
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;Stack (LIFO, parenthesis check, min stack)&lt;/li&gt;
&lt;li&gt;Queue (FIFO, circular queue, deque)&lt;/li&gt;
&lt;li&gt;Hash Table (frequency map, two sum)&lt;/li&gt;
&lt;li&gt;Trees: Binary Tree, Binary Search Tree&lt;/li&gt;
&lt;li&gt;Tree traversal: Inorder, Preorder, Postorder, Level Order&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;5 problems per topic&lt;/li&gt;
&lt;li&gt;TC/SC analysis + recursion where applicable&lt;/li&gt;
&lt;li&gt;Patterns: recursion in trees, hash map tricks&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Month 4: Advanced DS &amp;amp; Algorithms&lt;/strong&gt;
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;Heap (min/max heap, priority queue)&lt;/li&gt;
&lt;li&gt;Suffix Tree, Trie, Disjoint Set&lt;/li&gt;
&lt;li&gt;Graphs: BFS, DFS, shortest path&lt;/li&gt;
&lt;li&gt;Sorting: Merge, Quick, Heap&lt;/li&gt;
&lt;li&gt;Greedy, Backtracking, Dynamic Programming basics&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;5 problems per topic&lt;/li&gt;
&lt;li&gt;Analyze TC/SC + identify patterns (divide &amp;amp; conquer, memoization, greedy choice)&lt;/li&gt;
&lt;li&gt;Start with easy → medium → hard problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Daily/Weekly Practice Suggestion&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Daily:&lt;/strong&gt; 1–2 problems + TC/SC analysis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weekly:&lt;/strong&gt; 1 topic summary + patterns + mini project if possible&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monthly:&lt;/strong&gt; 2–3 mock problem sets (Leetcode/Hackerrank)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Extra Tips&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;JS&lt;/strong&gt; throughout (Node.js environment)&lt;/li&gt;
&lt;li&gt;Dry run solutions on paper before coding&lt;/li&gt;
&lt;li&gt;Note patterns + tricks in Notion for future reference&lt;/li&gt;
&lt;li&gt;Start integrating DSA in small projects (e.g., book management features)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datastructures</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>interview</category>
    </item>
    <item>
      <title>Frontend &amp; Java script Interview Questions</title>
      <dc:creator>Nitin Malviya</dc:creator>
      <pubDate>Mon, 27 Oct 2025 06:47:16 +0000</pubDate>
      <link>https://dev.to/nitinmalviy/frontend-java-script-interview-questions-1f9l</link>
      <guid>https://dev.to/nitinmalviy/frontend-java-script-interview-questions-1f9l</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Core JavaScript&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Difference between &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Explain &lt;code&gt;hoisting&lt;/code&gt; in JavaScript.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;===&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Explain &lt;code&gt;this&lt;/code&gt; keyword in different contexts (global, function, class, arrow function).&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;apply&lt;/code&gt;, and &lt;code&gt;bind&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Event bubbling vs event capturing.&lt;/li&gt;
&lt;li&gt;What is closure? Give example.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;forEach&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, &lt;code&gt;reduce&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;What is IIFE (Immediately Invoked Function Expression)?&lt;/li&gt;
&lt;li&gt;Difference between synchronous and asynchronous JavaScript.&lt;/li&gt;
&lt;li&gt;What is the event loop? Explain microtasks and macrotasks.&lt;/li&gt;
&lt;li&gt;Difference between shallow copy and deep copy — how to implement.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;Object.assign()&lt;/code&gt; and spread operator.&lt;/li&gt;
&lt;li&gt;Explain prototype and prototype chain.&lt;/li&gt;
&lt;li&gt;Explain ES6 modules and CommonJS modules difference.&lt;/li&gt;
&lt;li&gt;What are Promises and how do they work?&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;async/await&lt;/code&gt; and &lt;code&gt;.then/.catch()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;How does garbage collection work in JS?&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;for…in&lt;/code&gt; and &lt;code&gt;for…of&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced / Scenario-Based JS&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Implement debounce and throttle functions — explain use case.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;mutable&lt;/code&gt; and &lt;code&gt;immutable&lt;/code&gt; objects in JS.&lt;/li&gt;
&lt;li&gt;Explain memory leak scenarios in JS and how to prevent.&lt;/li&gt;
&lt;li&gt;Implement a function to deep clone nested objects.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;setTimeout(fn, 0)&lt;/code&gt; and &lt;code&gt;Promise.resolve().then(fn)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Explain Symbol and its usage.&lt;/li&gt;
&lt;li&gt;Difference between generator function and async generator.&lt;/li&gt;
&lt;li&gt;How to handle large array processing without blocking UI (chunking).&lt;/li&gt;
&lt;li&gt;Explain &lt;code&gt;WeakMap&lt;/code&gt; and &lt;code&gt;WeakSet&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;Object.freeze()&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; in objects.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Tricky JavaScript Questions (Advanced)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What's the output?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log(typeof typeof 1);&lt;br&gt;
   console.log(0.1 + 0.2 === 0.3);&lt;br&gt;
   console.log([] == ![]);&lt;br&gt;
   console.log(+'10' + 5);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Explain the execution order:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log('1');&lt;br&gt;
   setTimeout(() =&amp;gt; console.log('2'), 0);&lt;br&gt;
   Promise.resolve().then(() =&amp;gt; console.log('3'));&lt;br&gt;
   console.log('4');&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Temporal Dead Zone (TDZ)&lt;/strong&gt; — explain with example and why it exists.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What happens when you do this?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const obj = { a: 1 };&lt;br&gt;
   const arr = [obj, obj];&lt;br&gt;
   arr[0].a = 2;&lt;br&gt;
   console.log(arr[1].a); *// ?*&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain currying&lt;/strong&gt; — implement a curry function that works for any function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's wrong with this code?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 3; i++) {&lt;br&gt;
     setTimeout(() =&amp;gt; console.log(i), 100);&lt;br&gt;
   }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;How to fix it? (Multiple solutions)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Implement a pipe/compose function&lt;/strong&gt; — explain the difference.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain Proxy and Reflect API&lt;/strong&gt; — practical use case (e.g., validation).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What is the difference between &lt;code&gt;Object.create(null)&lt;/code&gt; and &lt;code&gt;{}&lt;/code&gt;?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a function that executes promises in sequence&lt;/strong&gt; (not parallel).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explain the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`function foo() { return { bar: "hello" }; }
function foo() { 
  return 
  { bar: "hello" }; 
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What is the &lt;code&gt;new&lt;/code&gt; keyword doing internally?&lt;/strong&gt; Implement your own &lt;code&gt;new&lt;/code&gt; operator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain tail call optimization&lt;/strong&gt; — does JS support it?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a memoization function&lt;/strong&gt; that works for any function with any number of arguments.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the output and why?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`const promise = new Promise((resolve) =&amp;gt; {
  console.log(1);
  resolve();
  console.log(2);
});
promise.then(() =&amp;gt; console.log(3));
console.log(4);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;How do you detect if a function is called with &lt;code&gt;new&lt;/code&gt;?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Implement &lt;code&gt;Promise.all&lt;/code&gt;, &lt;code&gt;Promise.race&lt;/code&gt;, and &lt;code&gt;Promise.allSettled&lt;/code&gt; from scratch.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What is the difference between &lt;code&gt;Promise.then()&lt;/code&gt; chaining and &lt;code&gt;async/await&lt;/code&gt; error propagation?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explain the "double equals quirks":&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`[] == ![] *// true*
{} == !{} *// false*
[] == [] *// false*`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What's the difference between &lt;code&gt;arguments&lt;/code&gt; and rest parameters?&lt;/strong&gt; Why avoid &lt;code&gt;arguments&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced Memory &amp;amp; Performance Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Memory leak scenario:&lt;/strong&gt; Event listeners not removed — how to detect and fix?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain V8's garbage collection algorithms:&lt;/strong&gt; Mark-and-sweep, Scavenge, Major GC.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to profile memory usage in Node.js?&lt;/strong&gt; Tools and approaches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What causes memory leaks in closures?&lt;/strong&gt; Give specific example.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain hidden classes and inline caching in V8&lt;/strong&gt; — how to write optimized code?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is the &lt;code&gt;-max-old-space-size&lt;/code&gt; flag?&lt;/strong&gt; When to use it?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How do you handle 10GB file processing in Node.js without loading it all into memory?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a LRU (Least Recently Used) cache&lt;/strong&gt; with O(1) get and put operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain memory fragmentation&lt;/strong&gt; — how does it affect Node.js applications?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How to detect and fix event loop blocking in production?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  React / Next.js / State Management Questions
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;React Core&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Difference between class components and functional components.&lt;/li&gt;
&lt;li&gt;What is virtual DOM and how React uses it?&lt;/li&gt;
&lt;li&gt;Explain React lifecycle methods (class) and hooks equivalents.&lt;/li&gt;
&lt;li&gt;Explain useState and useEffect — common pitfalls.&lt;/li&gt;
&lt;li&gt;Explain useMemo and useCallback — when and why to use.&lt;/li&gt;
&lt;li&gt;Difference between controlled and uncontrolled components.&lt;/li&gt;
&lt;li&gt;Explain React context API and its use case.&lt;/li&gt;
&lt;li&gt;How to prevent unnecessary re-renders in React.&lt;/li&gt;
&lt;li&gt;Difference between key props in lists — why important.&lt;/li&gt;
&lt;li&gt;Explain reconciliation in React.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;React Advanced / Optimization&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Explain code splitting and lazy loading in React.&lt;/li&gt;
&lt;li&gt;Difference between React.memo, PureComponent, and useMemo.&lt;/li&gt;
&lt;li&gt;How to optimize React app performance — list techniques.&lt;/li&gt;
&lt;li&gt;Explain event delegation in React.&lt;/li&gt;
&lt;li&gt;How to handle large forms efficiently.&lt;/li&gt;
&lt;li&gt;How to handle error boundaries in React.&lt;/li&gt;
&lt;li&gt;What is Suspense and Concurrent Mode in React.&lt;/li&gt;
&lt;li&gt;Difference between client-side rendering and server-side rendering.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;React Advanced &amp;amp; Tricky Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What's wrong with this code?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function Component() {&lt;br&gt;
     const [count, setCount] = useState(0);&lt;br&gt;
     const handleClick = () =&amp;gt; {&lt;br&gt;
       setCount(count + 1);&lt;br&gt;
       setCount(count + 1);&lt;br&gt;
       setCount(count + 1);&lt;br&gt;
     };&lt;br&gt;
     return &amp;lt;button onClick={handleClick}&amp;gt;{count}&amp;lt;/button&amp;gt;;&lt;br&gt;
   }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;How to fix it? Explain batching.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Explain the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect(() =&amp;gt; { */* ... */* }, []);&lt;br&gt;
   useEffect(() =&amp;gt; { */* ... */* });&lt;br&gt;
   useLayoutEffect(() =&amp;gt; { */* ... */* }, []);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Why is this an infinite loop?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect(() =&amp;gt; {&lt;br&gt;
     setData(fetchData());&lt;br&gt;
   }, [data]);&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Implement a custom hook for debounced value.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Component data={data} /&amp;gt;&lt;br&gt;
   &amp;lt;Component data={[...data]} /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain stale closures in React hooks&lt;/strong&gt; — give example and solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to share stateful logic between components without Context or Redux?&lt;/strong&gt; (Custom hooks)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What's the purpose of the &lt;code&gt;key&lt;/code&gt; prop in React?&lt;/strong&gt; Why not use index as key?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement useReducer from scratch&lt;/strong&gt; — explain when to use it over useState.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain React Fiber architecture&lt;/strong&gt; — how it enables concurrent rendering.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How does React decide when to batch state updates?&lt;/strong&gt; Automatic batching in React 18.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between &lt;code&gt;flushSync&lt;/code&gt; and normal state updates?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to prevent child component re-render when parent re-renders?&lt;/strong&gt; (Multiple techniques)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain React's reconciliation algorithm&lt;/strong&gt; — Diff algorithm in detail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens when you call setState in render method?&lt;/strong&gt; Why is it dangerous?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a custom &lt;code&gt;usePrevious&lt;/code&gt; hook&lt;/strong&gt; that returns previous value of a state.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How to handle race conditions in useEffect with API calls?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain ref forwarding and useImperativeHandle&lt;/strong&gt; — when to use?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between synthetic events and native events in React?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to optimize context to prevent unnecessary re-renders?&lt;/strong&gt; Split context technique.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Next.js Advanced Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Difference between SSR, SSG, ISR, and CSR in Next.js.&lt;/li&gt;
&lt;li&gt;Explain getServerSideProps vs getStaticProps.&lt;/li&gt;
&lt;li&gt;Explain API routes in Next.js.&lt;/li&gt;
&lt;li&gt;How to implement dynamic routing in Next.js.&lt;/li&gt;
&lt;li&gt;Explain Next.js image optimization.&lt;/li&gt;
&lt;li&gt;How to handle authentication in Next.js (JWT, cookies).&lt;/li&gt;
&lt;li&gt;Explain incremental static regeneration (ISR).&lt;/li&gt;
&lt;li&gt;How to optimize Next.js app performance (bundle splitting, caching).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Next.js Advanced &amp;amp; Tricky&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How does Next.js handle automatic code splitting?&lt;/strong&gt; Can you control it?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the difference between &lt;code&gt;next/link&lt;/code&gt; and regular anchor tags&lt;/strong&gt; — prefetching behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement middleware in Next.js 13+?&lt;/strong&gt; Use cases and limitations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain App Router vs Pages Router&lt;/strong&gt; — migration strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle environment variables securely in Next.js?&lt;/strong&gt; NEXT_PUBLIC_ prefix.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`export const revalidate = 60; *// ISR*
export const dynamic = 'force-dynamic'; *// SSR*
export const dynamic = 'force-static'; *// SSG*`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How to implement edge functions in Next.js?&lt;/strong&gt; Difference from serverless.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain streaming SSR in Next.js 13+&lt;/strong&gt; — Suspense boundaries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to optimize fonts in Next.js?&lt;/strong&gt; next/font system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens when you use &lt;code&gt;use client&lt;/code&gt; directive?&lt;/strong&gt; Bundle implications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle SEO for dynamic routes?&lt;/strong&gt; generateMetadata function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explain parallel and intercepting routes in App Router.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Redux / State Management&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Difference between Redux and React context.&lt;/li&gt;
&lt;li&gt;Explain Redux flow — actions, reducers, store.&lt;/li&gt;
&lt;li&gt;How to avoid unnecessary re-renders with Redux.&lt;/li&gt;
&lt;li&gt;Difference between middleware in Redux — thunk, saga.&lt;/li&gt;
&lt;li&gt;How to structure Redux state for large apps.&lt;/li&gt;
&lt;li&gt;Explain Redux Toolkit and why it's preferred.&lt;/li&gt;
&lt;li&gt;How to handle async API calls in Redux.&lt;/li&gt;
&lt;li&gt;How to persist Redux state in localStorage/sessionStorage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Redux Advanced &amp;amp; Tricky&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Why is Redux state immutable?&lt;/strong&gt; What happens if you mutate?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain Redux middleware&lt;/strong&gt; — implement a custom logger middleware.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`useSelector(state =&amp;gt; state.user)
useSelector(state =&amp;gt; ({ user: state.user }))`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;Re-render implications.&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How does Redux Toolkit's &lt;code&gt;createSlice&lt;/code&gt; work under the hood?&lt;/strong&gt; Immer integration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain Redux Saga effects:&lt;/strong&gt; &lt;code&gt;call&lt;/code&gt;, &lt;code&gt;put&lt;/code&gt;, &lt;code&gt;take&lt;/code&gt;, &lt;code&gt;fork&lt;/code&gt;, &lt;code&gt;spawn&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to handle optimistic updates in Redux?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What's the difference between &lt;code&gt;combineReducers&lt;/code&gt; and a single reducer?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to implement time-travel debugging?&lt;/strong&gt; Redux DevTools internals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain selectors and reselect library&lt;/strong&gt; — memoization benefits.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to handle authentication state in Redux?&lt;/strong&gt; Token refresh flow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What's the difference between Redux Thunk and Redux Saga?&lt;/strong&gt; When to use each?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to test Redux reducers and actions?&lt;/strong&gt; Best practices.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>programming</category>
      <category>interview</category>
    </item>
    <item>
      <title>Backend Interview Questions</title>
      <dc:creator>Nitin Malviya</dc:creator>
      <pubDate>Mon, 27 Oct 2025 06:45:32 +0000</pubDate>
      <link>https://dev.to/nitinmalviy/backend-interview-questions-2oo7</link>
      <guid>https://dev.to/nitinmalviy/backend-interview-questions-2oo7</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Core Node.js Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Node.js single-threaded hai — phir bhi multiple requests efficiently kaise handle karta hai? Explain event loop and non-blocking I/O.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;process.nextTick()&lt;/code&gt; and &lt;code&gt;setImmediate()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;How does Node.js handle 1000 concurrent requests? Explain async nature and event loop.&lt;/li&gt;
&lt;li&gt;Explain Event Loop phases.&lt;/li&gt;
&lt;li&gt;What are microtasks and macrotasks in Node.js? Give examples.&lt;/li&gt;
&lt;li&gt;How does Node.js handle CPU-intensive tasks?&lt;/li&gt;
&lt;li&gt;How do you debug performance issues (CPU/memory) in Node.js?&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;import&lt;/code&gt; in Node.js.&lt;/li&gt;
&lt;li&gt;Explain Streams in Node.js and give a scenario where they are useful.&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;fs.readFile&lt;/code&gt; and &lt;code&gt;fs.createReadStream&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Node.js Advanced &amp;amp; Tricky Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain the 6 phases of Node.js event loop in detail:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Timers&lt;/li&gt;
&lt;li&gt;Pending callbacks&lt;/li&gt;
&lt;li&gt;Idle, prepare&lt;/li&gt;
&lt;li&gt;Poll&lt;/li&gt;
&lt;li&gt;Check&lt;/li&gt;
&lt;li&gt;Close callbacks&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the order of execution?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`setImmediate(() =&amp;gt; console.log('immediate'));
process.nextTick(() =&amp;gt; console.log('nextTick'));
setTimeout(() =&amp;gt; console.log('timeout'), 0);
Promise.resolve().then(() =&amp;gt; console.log('promise'));
console.log('sync');`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How do you handle CPU-intensive tasks without blocking the event loop?&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Worker threads&lt;/li&gt;
&lt;li&gt;Child processes&lt;/li&gt;
&lt;li&gt;Clustering&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the difference between &lt;code&gt;fork()&lt;/code&gt;, &lt;code&gt;spawn()&lt;/code&gt;, &lt;code&gt;exec()&lt;/code&gt;, &lt;code&gt;execFile()&lt;/code&gt;&lt;/strong&gt; in child_process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is &lt;code&gt;libuv&lt;/code&gt;?&lt;/strong&gt; Role in Node.js architecture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How does Node.js utilize multiple CPU cores?&lt;/strong&gt; Cluster module.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain backpressure in streams&lt;/strong&gt; — how to handle it?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between readable, writable, duplex, and transform streams?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a custom transform stream&lt;/strong&gt; that converts input to uppercase.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How do you prevent thread starvation in Node.js?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain Node.js module resolution algorithm&lt;/strong&gt; — node_modules lookup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What's the purpose of &lt;code&gt;package-lock.json&lt;/code&gt;?&lt;/strong&gt; Difference from &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement graceful shutdown in Node.js?&lt;/strong&gt; Handle ongoing requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the &lt;code&gt;uncaughtException&lt;/code&gt; and &lt;code&gt;unhandledRejection&lt;/code&gt; events&lt;/strong&gt; — best practices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between &lt;code&gt;Buffer&lt;/code&gt; and &lt;code&gt;Uint8Array&lt;/code&gt;?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to detect memory leaks in production Node.js apps?&lt;/strong&gt; Tools: heapdump, clinic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain Node.js security best practices:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Helmet&lt;/li&gt;
&lt;li&gt;Rate limiting&lt;/li&gt;
&lt;li&gt;Input validation&lt;/li&gt;
&lt;li&gt;HTTPS&lt;/li&gt;
&lt;li&gt;Dependency scanning&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is N-API?&lt;/strong&gt; Native addons in Node.js.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How do you monitor Node.js application performance?&lt;/strong&gt; Metrics to track.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the &lt;code&gt;-inspect&lt;/code&gt; flag&lt;/strong&gt; — debugging production apps.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Express.js Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is middleware in Express? Types and examples.&lt;/li&gt;
&lt;li&gt;Explain error-handling middleware in Express.&lt;/li&gt;
&lt;li&gt;How to handle async errors in Express routes?&lt;/li&gt;
&lt;li&gt;How does Express handle routing internally?&lt;/li&gt;
&lt;li&gt;Difference between &lt;code&gt;app.use()&lt;/code&gt; and &lt;code&gt;router.use()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;How do you handle file uploads in Express?&lt;/li&gt;
&lt;li&gt;Explain rate limiting in Express — scenario where multiple requests come simultaneously.&lt;/li&gt;
&lt;li&gt;How to implement CORS in Express?&lt;/li&gt;
&lt;li&gt;How to secure Express app against common vulnerabilities (XSS, CSRF, SQL injection)?&lt;/li&gt;
&lt;li&gt;How do you implement logging in Express applications?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Express.js Advanced &amp;amp; Tricky&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What's the order of middleware execution?&lt;/strong&gt; How to control it?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How do you handle async errors without try-catch in every route?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`const asyncHandler = (fn) =&amp;gt; (req, res, next) =&amp;gt; {
  Promise.resolve(fn(req, res, next)).catch(next);
};`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain the request-response cycle in Express&lt;/strong&gt; — detailed flow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement custom middleware for authentication?&lt;/strong&gt; JWT verification.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between &lt;code&gt;app.route()&lt;/code&gt; and &lt;code&gt;router.route()&lt;/code&gt;?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle multipart/form-data?&lt;/strong&gt; Multer internals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a middleware that logs request time&lt;/strong&gt; for every route.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement CSRF protection?&lt;/strong&gt; Token-based approach.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explain the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`app.use('/api', router);
app.use(router);`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How to implement request validation?&lt;/strong&gt; Joi, express-validator.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens if you call &lt;code&gt;next()&lt;/code&gt; multiple times?&lt;/strong&gt; Common mistakes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement compression in Express?&lt;/strong&gt; gzip, brotli.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the &lt;code&gt;res.locals&lt;/code&gt; object&lt;/strong&gt; — use cases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement API versioning?&lt;/strong&gt; Multiple approaches.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between &lt;code&gt;res.send()&lt;/code&gt;, &lt;code&gt;res.json()&lt;/code&gt;, &lt;code&gt;res.end()&lt;/code&gt;?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;MongoDB / Mongoose Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Difference between &lt;code&gt;find()&lt;/code&gt;, &lt;code&gt;findOne()&lt;/code&gt;, and &lt;code&gt;findById()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Explain aggregation pipeline with an example.&lt;/li&gt;
&lt;li&gt;What is indexing? How does it improve query performance?&lt;/li&gt;
&lt;li&gt;What is &lt;code&gt;populate()&lt;/code&gt; in Mongoose? Give example.&lt;/li&gt;
&lt;li&gt;Difference between embedded documents and references.&lt;/li&gt;
&lt;li&gt;How to design schema for a blog or e-commerce app?&lt;/li&gt;
&lt;li&gt;How to handle large collections efficiently?&lt;/li&gt;
&lt;li&gt;Explain transactions in MongoDB and when to use them.&lt;/li&gt;
&lt;li&gt;How to implement pagination in MongoDB?&lt;/li&gt;
&lt;li&gt;How to handle schema validation in Mongoose?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;MongoDB Advanced &amp;amp; Tricky Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain MongoDB ACID properties&lt;/strong&gt; — transaction support.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`Model.find({})
Model.find({}).lean()
Model.find({}).cursor()`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How does MongoDB indexing work internally?&lt;/strong&gt; B-tree structure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain compound indexes&lt;/strong&gt; — order matters?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between covered query and indexed query?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement text search in MongoDB&lt;/strong&gt; — full-text search indexes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle schema versioning?&lt;/strong&gt; Migration strategies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain sharding in MongoDB&lt;/strong&gt; — when to use it?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between replica set and sharding?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to optimize aggregation pipeline performance?&lt;/strong&gt; &lt;code&gt;$match&lt;/code&gt; early, indexes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain the aggregation stages:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;$match&lt;/code&gt;, &lt;code&gt;$group&lt;/code&gt;, &lt;code&gt;$project&lt;/code&gt;, &lt;code&gt;$sort&lt;/code&gt;, &lt;code&gt;$limit&lt;/code&gt;, &lt;code&gt;$skip&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$lookup&lt;/code&gt; (joins), &lt;code&gt;$unwind&lt;/code&gt;, &lt;code&gt;$addFields&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement geospatial queries?&lt;/strong&gt; 2dsphere indexes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`{ $set: { name: 'John' } }
{ name: 'John' }`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;In update operations.&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain write concerns in MongoDB&lt;/strong&gt; — w, j, wtimeout.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to handle large file storage?&lt;/strong&gt; GridFS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What's the difference between &lt;code&gt;updateOne&lt;/code&gt;, &lt;code&gt;updateMany&lt;/code&gt;, &lt;code&gt;replaceOne&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement soft delete with Mongoose&lt;/strong&gt; — plugin approach.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;How to implement data auditing?&lt;/strong&gt; Timestamp tracking, change history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explain the Mongoose middleware&lt;/strong&gt; — pre/post hooks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What's the difference between:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`schema.virtual()
schema.method()
schema.static()`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Authentication / Authorization Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Explain JWT authentication flow.&lt;/li&gt;
&lt;li&gt;Difference between access token and refresh token.&lt;/li&gt;
&lt;li&gt;How to secure API routes in Express using JWT?&lt;/li&gt;
&lt;li&gt;How to implement role-based access control (RBAC) in Express?&lt;/li&gt;
&lt;li&gt;How to store JWT securely on client-side?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Auth Advanced &amp;amp; Tricky&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What's inside a JWT token?&lt;/strong&gt; Header, payload, signature — explain each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle token refresh without logout?&lt;/strong&gt; Refresh token rotation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between stateless and stateful authentication?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement OAuth 2.0 flow&lt;/strong&gt; — authorization code grant.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to prevent JWT replay attacks?&lt;/strong&gt; Nonce, jti claim.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Explain the difference between httpOnly and secure cookies.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement multi-factor authentication (MFA)?&lt;/strong&gt; TOTP algorithm.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between authentication and authorization?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement API key authentication?&lt;/strong&gt; Rate limiting per key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain session-based authentication&lt;/strong&gt; — vs JWT comparison.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle password reset securely?&lt;/strong&gt; Token expiration, one-time use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is bcrypt and why use it?&lt;/strong&gt; Salting, hashing rounds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement permission-based access control&lt;/strong&gt; — granular permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to secure refresh tokens?&lt;/strong&gt; Rotation, revocation strategies.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What's the difference between Bearer token and API key?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Scenario-Based / Practical Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Async/Await vs Promises in error handling — reusable async wrapper.&lt;/li&gt;
&lt;li&gt;MongoDB slow query on 1 million+ documents — how to optimize?&lt;/li&gt;
&lt;li&gt;User token expired — how to handle refresh token scenario?&lt;/li&gt;
&lt;li&gt;Multiple users uploading large files simultaneously — backend crash scenario, optimization.&lt;/li&gt;
&lt;li&gt;Aggregation: Top 3 users with highest total orders in last month.&lt;/li&gt;
&lt;li&gt;Public API exposed — prevent DDOS / brute force attacks using rate limiting.&lt;/li&gt;
&lt;li&gt;Express app running slow under load — how to debug performance issues.&lt;/li&gt;
&lt;li&gt;You need to migrate MongoDB schema without downtime — approach?&lt;/li&gt;
&lt;li&gt;Implement search functionality in MongoDB with text indexes.&lt;/li&gt;
&lt;li&gt;How to implement soft delete (logical delete) in MongoDB.&lt;/li&gt;
&lt;li&gt;Implement caching in Node.js for frequently accessed DB data (Redis / memory).&lt;/li&gt;
&lt;li&gt;Scenario: Real-time notifications using Node.js and MongoDB — approach.&lt;/li&gt;
&lt;li&gt;Scenario: File upload + image processing pipeline — handle asynchronously.&lt;/li&gt;
&lt;li&gt;Scenario: Multiple microservices interacting with one MongoDB — how to maintain consistency?&lt;/li&gt;
&lt;li&gt;Scenario: Multi-tenancy in Node.js + MongoDB application.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Extreme Scenario-Based Questions (Real Production Issues)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Your API suddenly returns 502 Bad Gateway for all requests&lt;/strong&gt; — where do you start debugging?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory usage keeps increasing in production Node.js app&lt;/strong&gt; — hits 2GB and crashes. How to debug?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database connection pool exhausted&lt;/strong&gt; — 100 concurrent users, all waiting. What's wrong?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Race condition in checkout system&lt;/strong&gt; — two users bought last item. How to prevent?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MongoDB aggregation taking 30+ seconds on 10M documents&lt;/strong&gt; — optimize without changing schema.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JWT token size causing performance issues&lt;/strong&gt; — payload too large. Solutions?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API rate limiter blocking legitimate users&lt;/strong&gt; — shared IP (corporate network). How to handle?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bulk email sending causing Express app to freeze&lt;/strong&gt; — 10,000 emails. Architecture solution?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File upload fails for files &amp;gt; 50MB&lt;/strong&gt; — timeout errors. Complete solution?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis cache hit rate is 5%&lt;/strong&gt; — supposed to be 80%+. What's wrong?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mongoose query returns all 1M documents instead of paginated results&lt;/strong&gt; — catastrophic error. Why?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebSocket connections keep dropping every 60 seconds&lt;/strong&gt; — load balancer issue?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database indexes not being used&lt;/strong&gt; — explain query plan shows COLLSCAN. Debug process?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrent API calls updating same document cause data loss&lt;/strong&gt; — optimistic locking solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication fails randomly for some users&lt;/strong&gt; — JWT verification errors. Debugging approach?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image processing queue backed up&lt;/strong&gt; — 10,000 pending jobs. How to handle gracefully?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Circular dependency in Node.js modules&lt;/strong&gt; — causing undefined exports. How to resolve?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API returns stale data despite database updates&lt;/strong&gt; — caching issue. Multi-layer cache invalidation strategy?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server crashes when processing CSV with 5M rows&lt;/strong&gt; — memory-efficient streaming solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;N+1 query problem in GraphQL&lt;/strong&gt; — 1000 database queries for single request. Solutions?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebSockets not scaling horizontally&lt;/strong&gt; — sticky sessions, Redis adapter solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction deadlock in MongoDB&lt;/strong&gt; — two operations waiting for each other. Prevention?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDN serving old JavaScript bundle&lt;/strong&gt; — aggressive caching. Cache busting strategies?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated tests passing but production failing&lt;/strong&gt; — environment differences. Investigation steps?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API response time increased from 100ms to 5s overnight&lt;/strong&gt; — no code changes. What to check?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;System Design &amp;amp; Architecture Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Design a URL shortener&lt;/strong&gt; (like bit.ly) — complete backend architecture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a rate limiter&lt;/strong&gt; — support distributed systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a real-time chat application&lt;/strong&gt; — WebSockets, scaling strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a file storage system&lt;/strong&gt; (like Dropbox) — chunking, deduplication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a notification system&lt;/strong&gt; — email, SMS, push notifications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design an e-commerce cart system&lt;/strong&gt; — handle race conditions, inventory management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a job queue system&lt;/strong&gt; — Bull, Redis, failure handling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design an analytics dashboard&lt;/strong&gt; — handling time-series data efficiently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a payment gateway integration&lt;/strong&gt; — security, idempotency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design a microservices architecture for a blog platform&lt;/strong&gt; — service boundaries, communication.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Performance &amp;amp; Optimization Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How to optimize a Next.js app that has 3-second initial load time?&lt;/strong&gt; Step-by-step approach.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API endpoint taking 10 seconds to respond&lt;/strong&gt; — profiling and optimization strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React app re-rendering 100 times on single user action&lt;/strong&gt; — identify and fix.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MongoDB query using 4GB of RAM&lt;/strong&gt; — aggregation optimization techniques.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js app using 100% CPU&lt;/strong&gt; — identify bottleneck without production downtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement caching strategy for REST API&lt;/strong&gt; — cache invalidation, TTL strategies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to reduce Docker image size from 2GB to 200MB?&lt;/strong&gt; Best practices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize bundle size in React app&lt;/strong&gt; — tree shaking, code splitting, dynamic imports.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database connection pool sizing&lt;/strong&gt; — how to determine optimal pool size?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement database read replicas&lt;/strong&gt; — read/write split in Node.js application.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;DevOps &amp;amp; Deployment Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explain CI/CD pipeline for Node.js application&lt;/strong&gt; — GitHub Actions, Jenkins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero-downtime deployment strategy&lt;/strong&gt; — blue-green, canary deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle environment variables securely?&lt;/strong&gt; Secrets management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain Docker multi-stage builds&lt;/strong&gt; — optimize image layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to monitor Node.js app in production?&lt;/strong&gt; PM2, New Relic, Prometheus.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement health check endpoint&lt;/strong&gt; — readiness vs liveness probes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle database migrations in production?&lt;/strong&gt; Rollback strategy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explain horizontal vs vertical scaling&lt;/strong&gt; — when to use each?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to implement logging in distributed systems?&lt;/strong&gt; Centralized logging (ELK stack).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Container orchestration&lt;/strong&gt; — Kubernetes basics for Node.js apps.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Code Review &amp;amp; Best Practices Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Review this code — find all issues:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app.get('/users/:id', (req, res) =&amp;gt; {&lt;br&gt;
     User.findById(req.params.id).then(user =&amp;gt; {&lt;br&gt;
       res.json(user);&lt;br&gt;
     });&lt;br&gt;
   });&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What's wrong with this Mongoose schema?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const userSchema = new Schema({&lt;br&gt;
     email: String,&lt;br&gt;
     password: String&lt;br&gt;
   });&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Review this React component:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function List({ items }) {&lt;br&gt;
     return items.map(item =&amp;gt; &amp;lt;div&amp;gt;{item.name}&amp;lt;/div&amp;gt;);&lt;br&gt;
   }&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;What's the security issue here?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;app.get('/search', (req, res) =&amp;gt; {&lt;br&gt;
     const query = req.query.q;&lt;br&gt;
     db.collection('posts').find({ $where: query });&lt;br&gt;
   });&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Identify the performance problem:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect(() =&amp;gt; {&lt;br&gt;
     const data = expensiveOperation();&lt;br&gt;
     setData(data);&lt;br&gt;
   });&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Testing Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;How to test async Express routes?&lt;/strong&gt; Jest, Supertest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Difference between unit, integration, and E2E tests&lt;/strong&gt; — examples for each.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to mock MongoDB in tests?&lt;/strong&gt; mongodb-memory-server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing React components&lt;/strong&gt; — React Testing Library best practices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to test private functions?&lt;/strong&gt; Should you test them?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement test coverage&lt;/strong&gt; — what percentage is ideal?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to test error scenarios?&lt;/strong&gt; Error boundaries, API failures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing WebSocket connections&lt;/strong&gt; — approach and tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to handle flaky tests?&lt;/strong&gt; Identification and fixes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test database transactions&lt;/strong&gt; — rollback after each test.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Bonus: Algorithm &amp;amp; Data Structure Questions&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Implement LRU Cache&lt;/strong&gt; — O(1) get and put.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two Sum problem&lt;/strong&gt; — optimal solution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reverse a linked list&lt;/strong&gt; — iterative and recursive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate balanced parentheses&lt;/strong&gt; — stack approach.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Find duplicate in array&lt;/strong&gt; — without extra space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement debounce and throttle&lt;/strong&gt; — from scratch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Binary search&lt;/strong&gt; — find element in sorted array.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge two sorted arrays&lt;/strong&gt; — in-place.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implement a trie (prefix tree)&lt;/strong&gt; — autocomplete use case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Detect cycle in linked list&lt;/strong&gt; — Floyd's algorithm.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>node</category>
      <category>express</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
