<?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: Himanshu Singh Tomar</title>
    <description>The latest articles on DEV Community by Himanshu Singh Tomar (@himanshusinghtomar).</description>
    <link>https://dev.to/himanshusinghtomar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1042705%2F89036594-4ef5-4129-9e20-adb26b85eb25.jpeg</url>
      <title>DEV Community: Himanshu Singh Tomar</title>
      <link>https://dev.to/himanshusinghtomar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshusinghtomar"/>
    <language>en</language>
    <item>
      <title>Transformers Are Not Dead — But Hybrids Are the Future. Here's Why.</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Mon, 23 Mar 2026 06:17:55 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/transformers-are-not-dead-but-hybrids-are-the-future-heres-why-540g</link>
      <guid>https://dev.to/himanshusinghtomar/transformers-are-not-dead-but-hybrids-are-the-future-heres-why-540g</guid>
      <description>&lt;p&gt;I've been spending a lot of time recently understanding how the next generation of AI models are being built. Not just using them — actually understanding what's happening under the hood.&lt;/p&gt;

&lt;p&gt;And here's what I've realized: &lt;strong&gt;the Transformer isn't going anywhere. But it's also not enough on its own anymore.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me explain.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem Nobody Talks About
&lt;/h2&gt;

&lt;p&gt;Every major LLM today — GPT-4, Claude, Gemini, Llama — is built on the Transformer architecture. It works. It works incredibly well. But it has one fundamental problem that gets worse as we push for longer contexts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Self-attention is O(L²).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That means if you double your context window from 64K to 128K tokens, the compute doesn't just double — it &lt;strong&gt;quadruples&lt;/strong&gt;. And the KV cache (the memory that stores past token information during inference) grows linearly with sequence length.&lt;/p&gt;

&lt;p&gt;At 128K context with a 32-layer Transformer, you're looking at roughly &lt;strong&gt;128 GB of KV cache&lt;/strong&gt;. That's not fitting on a single GPU.&lt;/p&gt;

&lt;p&gt;This is where Mamba enters the picture. And this is where things get interesting.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 1: The Transformer — What You Already Use
&lt;/h2&gt;

&lt;p&gt;Let me break down what's actually happening inside a Transformer. If you've used any modern LLM, this is the engine running underneath.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Full Architecture
&lt;/h3&gt;

&lt;p&gt;The original Transformer (Vaswani et al., 2017 — "Attention Is All You Need") has two halves — an Encoder and a Decoder:&lt;/p&gt;

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

&lt;p&gt;Most modern LLMs (GPT, Llama, Claude) use &lt;strong&gt;decoder-only&lt;/strong&gt; Transformers — they drop the encoder entirely and just stack decoder layers. But the core mechanism is the same.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Self-Attention Actually Works
&lt;/h3&gt;

&lt;p&gt;This is the heart of the Transformer. Let me walk through it with a concrete example.&lt;/p&gt;

&lt;p&gt;Say you have the sentence: &lt;strong&gt;"The cat sat on it"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the model processes the token "it", it needs to figure out: what does "it" refer to?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Each token creates three vectors from its embedding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Query (Q)&lt;/strong&gt; — "What am I looking for?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key (K)&lt;/strong&gt; — "What do I contain?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Value (V)&lt;/strong&gt; — "What information do I carry?"&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Compute attention scores = dot product of Q("it") with K(every other token):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
    T1["The = 0.05"]
    T2["cat = 0.72"]
    T3["sat = 0.12"]
    T4["on = 0.03"]
    T5["it = 0.08"]

    classDef low fill:#f1f5f9,stroke:#94a3b8,color:#334155
    classDef high fill:#c084fc,stroke:#9333ea,stroke-width:3px,color:#3b0764

    class T1,T3,T4,T5 low
    class T2 high
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Softmax normalizes scores into attention weights (sum = 1.0)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Output = weighted sum of all Value vectors&lt;/p&gt;

&lt;p&gt;The result? "it" attends most strongly to "cat" (weight 0.72) — &lt;strong&gt;it learned that "it" refers to "the cat"&lt;/strong&gt; without anyone telling it to. That's the magic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Multi-Head Attention
&lt;/h3&gt;

&lt;p&gt;The model runs this process multiple times in parallel (typically 8-16 heads). Each head learns different relationships:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  The Feed-Forward Network
&lt;/h3&gt;

&lt;p&gt;After attention, each token goes through a two-layer MLP independently:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FFN(x) = max(0, x·W₁ + b₁)·W₂ + b₂&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is where the model stores &lt;strong&gt;factual knowledge&lt;/strong&gt; — it acts like a key-value memory. Research has shown you can actually locate specific facts in specific neurons of the FFN layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Residual Connections + Layer Norm
&lt;/h3&gt;

&lt;p&gt;Every sub-layer is wrapped with: &lt;code&gt;LayerNorm(x + SubLayer(x))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This prevents gradient degradation through deep stacks. Without residuals, gradients would vanish by layer 10. With them, you can stack 80+ layers.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Cost
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Training Cost&lt;/th&gt;
&lt;th&gt;Inference (per token)&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Self-Attention&lt;/td&gt;
&lt;td&gt;O(L²·d)&lt;/td&gt;
&lt;td&gt;O(L·d)&lt;/td&gt;
&lt;td&gt;O(L·d) KV cache&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FFN&lt;/td&gt;
&lt;td&gt;O(L·d²)&lt;/td&gt;
&lt;td&gt;O(d²)&lt;/td&gt;
&lt;td&gt;O(d²) weights&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That &lt;strong&gt;L²&lt;/strong&gt; in attention is the killer. Everything else scales linearly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 2: Mamba — The Challenger
&lt;/h2&gt;

&lt;p&gt;Mamba was introduced by Albert Gu and Tri Dao in December 2023. It takes a completely different approach: instead of letting every token look at every other token, it processes the sequence through a &lt;strong&gt;Selective State Space Model (SSM)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Core Idea: A Learned Compression
&lt;/h3&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Transformer&lt;/strong&gt;: keeps a complete photo album of every past token (KV cache)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mamba&lt;/strong&gt;: keeps a single, constantly-updated summary note (hidden state)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The math comes from continuous dynamical systems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Continuous form:
  h'(t) = A·h(t) + B·x(t)     ← hidden state evolution
  y(t)  = C·h(t)               ← output

Discretized (for actual tokens):
  h_t = A_bar · h_(t-1) + B_bar · x_t   ← update hidden state
  y_t = C · h_t                          ← read output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A (transition/decay matrix)&lt;/strong&gt; — controls how much old state is retained&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;B (input matrix)&lt;/strong&gt; — controls how much of the new token gets written in&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C (output matrix)&lt;/strong&gt; — controls what gets read out&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delta (step size)&lt;/strong&gt; — controls discretization granularity&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Makes Mamba Different: Selectivity
&lt;/h3&gt;

&lt;p&gt;Previous state space models (S4, H3) used &lt;strong&gt;fixed&lt;/strong&gt; A, B, C parameters — same for every token. Mamba's key innovation: &lt;strong&gt;these parameters are input-dependent&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;This is &lt;strong&gt;selectivity&lt;/strong&gt;. The model dynamically decides, per-token:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When to remember (small Delta = gentle update)&lt;/li&gt;
&lt;li&gt;When to forget (large Delta = aggressive reset)&lt;/li&gt;
&lt;li&gt;What to write (B controls input projection)&lt;/li&gt;
&lt;li&gt;What to output (C controls readout)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A delimiter token might trigger high forgetting. A content word triggers careful accumulation. The model learns this entirely from data.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Mamba Block
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TB
    INPUT["Input - B, L, D"] --&amp;gt; NORM["RMS Norm"]
    NORM --&amp;gt; LP1["Branch A: Linear Proj D to E"]
    NORM --&amp;gt; LP2["Branch B: Linear Proj D to E - gate"]

    LP1 --&amp;gt; CONV["Causal Conv1D kernel=4"]
    CONV --&amp;gt; SILU1["SiLU Activation"]
    SILU1 --&amp;gt; SSSM["SELECTIVE SSM - Input-dependent A, B, C, Delta"]

    LP2 --&amp;gt; SILU2["SiLU Activation"]

    SSSM --&amp;gt; MUL["Multiply - Gating"]
    SILU2 --&amp;gt; MUL

    MUL --&amp;gt; LP3["Linear Proj E to D"]
    LP3 --&amp;gt; RES["Residual Add"]
    INPUT -.-&amp;gt;|"Skip connection"| RES
    RES --&amp;gt; OUT["Output - B, L, D"]

    classDef neutral fill:#f1f5f9,stroke:#64748b,color:#1e293b
    classDef norm fill:#e2e8f0,stroke:#64748b,color:#1e293b
    classDef proj fill:#dbeafe,stroke:#3b82f6,color:#1e3a5f
    classDef conv fill:#fed7aa,stroke:#f97316,stroke-width:2px,color:#7c2d12
    classDef ssm fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#7f1d1d
    classDef gate fill:#fce7f3,stroke:#ec4899,stroke-width:2px,color:#831843
    classDef res fill:#d1fae5,stroke:#10b981,color:#064e3b

    class INPUT,OUT neutral
    class NORM,SILU1,SILU2 norm
    class LP1,LP2,LP3 proj
    class CONV conv
    class SSSM ssm
    class MUL gate
    class RES res
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The split-branch design is key: one path does the heavy computation (Conv1D followed by SSM), the other acts as a gate. Multiplying them together gives the model fine control over information flow.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Hardware Trick: Parallel Scan
&lt;/h3&gt;

&lt;p&gt;"But wait," you're thinking, "if Mamba processes tokens sequentially through a recurrence, isn't training slow?"&lt;/p&gt;

&lt;p&gt;Here's the engineering brilliance: the state update is &lt;strong&gt;associative&lt;/strong&gt;. That means you can parallelize it using a scan (prefix sum) operation — the same algorithm GPUs are incredibly good at.&lt;/p&gt;

&lt;p&gt;During training, Mamba achieves near-Transformer parallelism. During inference, it's purely recurrent — just update the hidden state with each new token. &lt;strong&gt;No KV cache. Constant memory. Constant time per token.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Hidden State Flow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
    X1["x1"] --&amp;gt;|"B"| H1["h1"]
    X2["x2"] --&amp;gt;|"B"| H2["h2"]
    X3["x3"] --&amp;gt;|"B"| H3["h3"]
    X4["x4"] --&amp;gt;|"B"| H4["h4"]
    X5["x5"] --&amp;gt;|"B"| H5["h5"]

    H1 --&amp;gt;|"A decay"| H2
    H2 --&amp;gt;|"A decay"| H3
    H3 --&amp;gt;|"A decay"| H4
    H4 --&amp;gt;|"A decay"| H5

    H1 --&amp;gt;|"C"| Y1["y1"]
    H2 --&amp;gt;|"C"| Y2["y2"]
    H3 --&amp;gt;|"C"| Y3["y3"]
    H4 --&amp;gt;|"C"| Y4["y4"]
    H5 --&amp;gt;|"C"| Y5["y5"]

    classDef inp fill:#fef3c7,stroke:#f59e0b,color:#78350f
    classDef hid fill:#ccfbf1,stroke:#14b8a6,stroke-width:2px,color:#134e4a
    classDef outp fill:#e0e7ff,stroke:#6366f1,color:#312e81

    class X1,X2,X3,X4,X5 inp
    class H1,H2,H3,H4,H5 hid
    class Y1,Y2,Y3,Y4,Y5 outp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each hidden state &lt;code&gt;h_t&lt;/code&gt; carries a compressed summary of all past tokens. The A matrix controls decay (how much old info fades), B controls what gets written in, C controls what gets read out. All input-dependent in Mamba.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Cost
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Training Cost&lt;/th&gt;
&lt;th&gt;Inference (per token)&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Selective SSM&lt;/td&gt;
&lt;td&gt;O(L·d) linear&lt;/td&gt;
&lt;td&gt;O(d) constant&lt;/td&gt;
&lt;td&gt;O(N·d) fixed state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Conv1D&lt;/td&gt;
&lt;td&gt;O(L·d)&lt;/td&gt;
&lt;td&gt;O(d)&lt;/td&gt;
&lt;td&gt;O(k·d) kernel&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Everything is linear or constant. No quadratic anywhere.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 3: The Head-to-Head Comparison
&lt;/h2&gt;

&lt;p&gt;Let me be real about where each architecture wins and loses:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Transformer&lt;/th&gt;
&lt;th&gt;Mamba&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Core mechanism&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Self-attention (token-to-token)&lt;/td&gt;
&lt;td&gt;Selective SSM (compressed state)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Training compute&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;O(L²·d) quadratic&lt;/td&gt;
&lt;td&gt;O(L·d) linear&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Inference per token&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;O(L·d) grows with context&lt;/td&gt;
&lt;td&gt;O(d) constant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Memory (KV cache)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;O(L·d) grows&lt;/td&gt;
&lt;td&gt;O(N·d) fixed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Context window&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fixed (4K-128K) hard wall&lt;/td&gt;
&lt;td&gt;Theoretically unlimited&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Exact retrieval&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Perfect — can pinpoint any token&lt;/td&gt;
&lt;td&gt;Lossy — compressed into finite state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;In-context learning&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Strong — dynamic pattern routing&lt;/td&gt;
&lt;td&gt;Weaker on exact copy/retrieval&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scale proven&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;400B+ parameters&lt;/td&gt;
&lt;td&gt;Up to ~8B so far&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ecosystem&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mature (FlashAttention, vLLM)&lt;/td&gt;
&lt;td&gt;Newer, custom CUDA kernels&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The Fundamental Tradeoff
&lt;/h3&gt;

&lt;p&gt;It comes down to this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Attention = complete, addressable memory of every past token. You pay O(L²) for it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SSM = fixed-size compressed summary of history. Much cheaper, but lossy.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The question is: &lt;strong&gt;is that compression sufficient for the task at hand?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For most of the computation in a forward pass — yes. You don't need to look at every single past token to process the word "the". But for some critical operations — resolving coreferences, copying exact numbers, following specific instructions — you need the precision of attention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And that's exactly why hybrids are the answer.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 4: The Hybrid Architecture — Best of Both Worlds
&lt;/h2&gt;

&lt;p&gt;This is where I got really excited. The hybrid approach isn't a compromise — it's genuinely better than either architecture alone.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Core Insight
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;You don't need quadratic attention at every single layer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most layers are doing local, incremental processing. Mamba handles this beautifully at linear cost. But at certain critical points, you need the model to "check its work" against the full context with exact attention.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jamba: The Reference Implementation
&lt;/h3&gt;

&lt;p&gt;AI21 Labs built Jamba — the first production-scale hybrid (52B total / 12B active, 256K context). Here's the layer stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TB
    INPUT["Token Embedding"] --&amp;gt; M1

    subgraph BLOCK1["Layers 1-7 : Mamba Foundation"]
        M1["Mamba SSM + Dense FFN"]
        M2["Mamba SSM + Dense FFN"]
        M3["... x 7 layers total"]
    end

    M3 --&amp;gt; A1

    subgraph ATTN1["Layer 8 : Attention Checkpoint"]
        A1["Self-Attention + MoE FFN -- KV cache stored"]
    end

    A1 --&amp;gt; M4

    subgraph BLOCK2["Layers 9-15 : Mamba Efficient Flow"]
        M4["Mamba SSM + MoE FFN"]
        M5["Mamba SSM + MoE FFN"]
        M6["... x 7 layers total"]
    end

    M6 --&amp;gt; A2

    subgraph ATTN2["Layer 16 : Attention Checkpoint"]
        A2["Self-Attention + MoE FFN -- KV cache stored"]
    end

    A2 --&amp;gt; M7

    subgraph BLOCK3["Layers 17-23 : Mamba Efficient Flow"]
        M7["... x 7 Mamba SSM layers"]
    end

    M7 --&amp;gt; A3

    subgraph ATTN3["Layer 24 : Attention Checkpoint"]
        A3["Self-Attention + MoE FFN"]
    end

    A3 --&amp;gt; M8

    subgraph BLOCK4["Layers 25-31 : Mamba Efficient Flow"]
        M8["... x 7 Mamba SSM layers"]
    end

    M8 --&amp;gt; A4

    subgraph ATTN4["Layer 32 : Attention Checkpoint"]
        A4["Self-Attention + MoE FFN"]
    end

    A4 --&amp;gt; NORM["RMS Norm + Linear Head"]
    NORM --&amp;gt; OUTPUT["Output Logits"]

    classDef mambaBlock fill:#d1fae5,stroke:#10b981,stroke-width:2px,color:#064e3b
    classDef attnBlock fill:#ede9fe,stroke:#8b5cf6,stroke-width:2px,color:#3b1f7e
    classDef mambaNode fill:#a7f3d0,stroke:#059669,color:#064e3b
    classDef attnNode fill:#c4b5fd,stroke:#7c3aed,color:#3b1f7e
    classDef ioNode fill:#fef3c7,stroke:#f59e0b,color:#78350f
    classDef normNode fill:#e2e8f0,stroke:#64748b,color:#1e293b

    class BLOCK1,BLOCK2,BLOCK3,BLOCK4 mambaBlock
    class ATTN1,ATTN2,ATTN3,ATTN4 attnBlock
    class M1,M2,M3,M4,M5,M6,M7,M8 mambaNode
    class A1,A2,A3,A4 attnNode
    class INPUT,OUTPUT ioNode
    class NORM normNode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pattern:&lt;/strong&gt; 7 Mamba layers followed by 1 Attention layer, repeat. That's &lt;strong&gt;87.5% Mamba, 12.5% Attention&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why This Pattern Works
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mamba layers (87.5% of the stack)&lt;/strong&gt; handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local patterns and syntax&lt;/li&gt;
&lt;li&gt;Sequential information flow&lt;/li&gt;
&lt;li&gt;Building up contextual representations&lt;/li&gt;
&lt;li&gt;General "thinking" that doesn't need exact retrieval&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Attention layers (12.5% of the stack)&lt;/strong&gt; handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disambiguating words ("bank" = river bank or financial bank?)&lt;/li&gt;
&lt;li&gt;Coreference resolution ("it" → "the cat")&lt;/li&gt;
&lt;li&gt;Exact information retrieval from context&lt;/li&gt;
&lt;li&gt;Following specific instructions from the prompt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Mamba layers &lt;strong&gt;enrich the token representations&lt;/strong&gt; before they hit the attention layer. By the time attention fires, the representations are already pretty good — attention just needs to do targeted cleanup and retrieval.&lt;/p&gt;

&lt;h3&gt;
  
  
  The MoE Layer: The Third Ingredient
&lt;/h3&gt;

&lt;p&gt;Jamba also uses Mixture of Experts (MoE) in its feed-forward layers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TD
    TOKEN["Input Token"] --&amp;gt; ROUTER["Router Network - scores all 16 experts"]
    ROUTER --&amp;gt;|"Selected"| E3["Expert 3 - active"]
    ROUTER --&amp;gt;|"Selected"| E11["Expert 11 - active"]
    ROUTER -.-&amp;gt;|"Not selected"| E1["Expert 1"]
    ROUTER -.-&amp;gt;|"Not selected"| E2["Expert 2"]
    ROUTER -.-&amp;gt;|"..."| E16["Expert 16"]
    E3 --&amp;gt; SUM["Weighted Sum"]
    E11 --&amp;gt; SUM
    SUM --&amp;gt; OUT["Output"]

    classDef token fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#78350f
    classDef router fill:#fecaca,stroke:#ef4444,stroke-width:2px,color:#7f1d1d
    classDef active fill:#bbf7d0,stroke:#22c55e,stroke-width:2px,color:#14532d
    classDef inactive fill:#f1f5f9,stroke:#cbd5e1,color:#94a3b8
    classDef sum fill:#dbeafe,stroke:#3b82f6,color:#1e3a5f
    classDef neutral fill:#f1f5f9,stroke:#64748b,color:#1e293b

    class TOKEN token
    class ROUTER router
    class E3,E11 active
    class E1,E2,E16 inactive
    class SUM sum
    class OUT neutral
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;16 experts total, 2 active per token.&lt;/strong&gt; This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Total parameters: 52B (lots of knowledge capacity)&lt;/li&gt;
&lt;li&gt;Active parameters per token: 12B (fast inference)&lt;/li&gt;
&lt;li&gt;Each expert can specialize (math, code, language, reasoning, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Memory Savings Are Massive
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
    subgraph TRANSFORMER["Pure Transformer - 32 layers"]
        T1["32 attention layers | 32 KV caches | ~128 GB at 256K | Needs multiple GPUs"]
    end

    subgraph HYBRID["Jamba Hybrid - 32 layers"]
        H1["4 attn + 28 Mamba | 4 KV caches | ~16 GB at 256K | Single 80GB GPU"]
    end

    TRANSFORMER --&amp;gt;|"8x memory reduction"| HYBRID

    classDef bad fill:#fecaca,stroke:#ef4444,stroke-width:2px,color:#7f1d1d
    classDef good fill:#bbf7d0,stroke:#22c55e,stroke-width:2px,color:#14532d
    classDef badNode fill:#fee2e2,stroke:#ef4444,color:#7f1d1d
    classDef goodNode fill:#dcfce7,stroke:#22c55e,color:#14532d

    class TRANSFORMER bad
    class HYBRID good
    class T1 badNode
    class H1 goodNode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the difference between needing a cluster and fitting on a single GPU.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 5: How Data Flows Through a Hybrid
&lt;/h2&gt;

&lt;p&gt;Let me trace what happens when you send &lt;strong&gt;"The bank of the river was steep and muddy"&lt;/strong&gt; through a hybrid model:&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1: Mamba Layers Build Compressed Context
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
    H1["h: the bank..."] --&amp;gt;|"A decay"| H2["h: bank of river..."]
    H2 --&amp;gt;|"A decay"| H3["h: river was steep..."]
    H3 --&amp;gt;|"A decay"| H4["h: steep and..."]

    classDef s1 fill:#a7f3d0,stroke:#059669,color:#064e3b
    classDef s2 fill:#6ee7b7,stroke:#059669,color:#064e3b
    classDef s3 fill:#34d399,stroke:#059669,color:#064e3b
    classDef s4 fill:#10b981,stroke:#047857,color:#f0fdf4

    class H1 s1
    class H2 s2
    class H3 s3
    class H4 s4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good at: local patterns, syntax, general context. Weak at: pinpointing a specific distant token.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 2: Attention Layer Resolves Ambiguities
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TD
    AND["and - query token"] --&amp;gt;|"weight: 0.35"| STEEP["steep"]
    AND --&amp;gt;|"weight: 0.28"| RIVER["river"]
    AND --&amp;gt;|"weight: 0.22"| BANK["bank"]
    AND --&amp;gt;|"weight: 0.08"| WAS["was"]

    BANK2["bank - query"] --&amp;gt;|"weight: 0.65 STRONG"| RIVER2["river - disambiguates!"]
    BANK2 --&amp;gt;|"weight: 0.12"| OF["of"]
    BANK2 --&amp;gt;|"weight: 0.10"| THE["the"]

    classDef query fill:#fef3c7,stroke:#f59e0b,stroke-width:2px,color:#78350f
    classDef high fill:#c4b5fd,stroke:#8b5cf6,color:#3b1f7e
    classDef mid fill:#93c5fd,stroke:#3b82f6,color:#1e3a5f
    classDef low fill:#f1f5f9,stroke:#94a3b8,color:#334155
    classDef match fill:#fecaca,stroke:#ef4444,stroke-width:3px,color:#7f1d1d

    class AND,BANK2 query
    class STEEP high
    class RIVER,BANK mid
    class WAS,OF,THE low
    class RIVER2 match
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This is the checkpoint moment.&lt;/strong&gt; "bank" attends to "river" with weight 0.65 — it gets disambiguated as "river bank", not "financial bank". After this layer, the representation is precise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 3-4: More Mamba → More Attention → Repeat
&lt;/h3&gt;

&lt;p&gt;Back to efficient Mamba processing, now with enriched representations. The disambiguation carries forward. Next attention checkpoint does higher-level reasoning.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 6: The Three Design Decisions
&lt;/h2&gt;

&lt;p&gt;If you're building or fine-tuning a hybrid model, these are the knobs:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Attention-to-Mamba Ratio
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
    TOO_MUCH["Too much attention - back to Transformer costs"] --- SWEET["Sweet spot 1:6 to 1:8 - best tradeoff"] --- TOO_LITTLE["Too little attention - retrieval quality drops"]

    classDef bad fill:#fecaca,stroke:#ef4444,color:#7f1d1d
    classDef good fill:#bbf7d0,stroke:#22c55e,stroke-width:2px,color:#14532d

    class TOO_MUCH,TOO_LITTLE bad
    class SWEET good
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Where to Place Attention Layers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Early layers&lt;/strong&gt; learn low-level features (syntax, local patterns) → Mamba handles fine&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep layers&lt;/strong&gt; handle abstract reasoning, long-range deps → attention more valuable&lt;/li&gt;
&lt;li&gt;Jamba distributes evenly (every 8th layer)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. MoE vs Dense FFN
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;First few layers&lt;/strong&gt;: Dense FFN (shared features needed by all tokens)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Later layers&lt;/strong&gt;: MoE (specialized knowledge, different tokens need different experts)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Part 7: Other Hybrid Models to Watch
&lt;/h2&gt;

&lt;p&gt;Jamba isn't alone. The hybrid approach is becoming a movement:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Key Innovation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Jamba&lt;/strong&gt; (AI21)&lt;/td&gt;
&lt;td&gt;Mamba + Attention + MoE&lt;/td&gt;
&lt;td&gt;First production hybrid, 256K context&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Zamba&lt;/strong&gt; (Zyphra)&lt;/td&gt;
&lt;td&gt;Mamba + shared attention&lt;/td&gt;
&lt;td&gt;Shared KV cache across attention insertion points&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Griffin&lt;/strong&gt; (DeepMind)&lt;/td&gt;
&lt;td&gt;Gated linear recurrence + attention&lt;/td&gt;
&lt;td&gt;Google's take on efficient recurrence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;RWKV-6&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linear attention + recurrence&lt;/td&gt;
&lt;td&gt;Open-source, Transformer-quality at linear cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Mamba-2&lt;/strong&gt; (Gu &amp;amp; Dao)&lt;/td&gt;
&lt;td&gt;Improved SSM as structured matrix mult&lt;/td&gt;
&lt;td&gt;Faster hardware utilization, easier hybridization&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Part 8: The Future — My Take
&lt;/h2&gt;

&lt;p&gt;Here's what I think is going to happen in the next 1-2 years:&lt;/p&gt;

&lt;h3&gt;
  
  
  Transformers Are NOT Dead
&lt;/h3&gt;

&lt;p&gt;Let me be clear. Transformers won't die. They're:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proven at 400B+ parameter scale&lt;/li&gt;
&lt;li&gt;Backed by massive ecosystem (FlashAttention, vLLM, TensorRT, ONNX)&lt;/li&gt;
&lt;li&gt;Still the best at tasks requiring precise information routing&lt;/li&gt;
&lt;li&gt;The architecture behind every frontier model today&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You can't just throw away 7+ years of engineering and optimization.&lt;/strong&gt; The tooling, the infrastructure, the deployment pipelines — all built for Transformers.&lt;/p&gt;

&lt;h3&gt;
  
  
  But Pure Transformers Are Over-Engineered
&lt;/h3&gt;

&lt;p&gt;Here's the thing: &lt;strong&gt;most of the computation in a Transformer is wasted.&lt;/strong&gt; Not every layer needs quadratic attention. Not every token needs to look at every other token at every layer.&lt;/p&gt;

&lt;p&gt;The research is converging on a clear signal: &lt;strong&gt;use the minimum attention necessary, fill the rest with efficient recurrence.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Hybrids Are the Path Forward
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TD
    F1["Frontier labs adopt hybrids -- 8x memory savings too compelling"]
    F2["Attention becomes premium -- used sparingly like DB indexes"]
    F3["Open-source hybrids close the gap -- Mamba + RWKV already open"]
    F4["1M+ context windows standard -- constant-memory inference"]
    F5["New hardware optimizations -- custom silicon for selective scan"]
    F6["Cost per token drops -- model tiering strategies evolve"]

    classDef c1 fill:#dbeafe,stroke:#3b82f6,color:#1e3a5f
    classDef c2 fill:#e0e7ff,stroke:#6366f1,color:#312e81
    classDef c3 fill:#d1fae5,stroke:#10b981,color:#064e3b
    classDef c4 fill:#fef3c7,stroke:#f59e0b,color:#78350f
    classDef c5 fill:#fce7f3,stroke:#ec4899,color:#831843
    classDef c6 fill:#ccfbf1,stroke:#14b8a6,color:#134e4a

    class F1 c1
    class F2 c2
    class F3 c3
    class F4 c4
    class F5 c5
    class F6 c6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Us Developers
&lt;/h3&gt;

&lt;p&gt;The architectural shift means real changes in how we build:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cost per token will drop&lt;/strong&gt; — hybrid models need less compute&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Context windows will explode&lt;/strong&gt; — entire codebases in context becomes feasible&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time apps become easier&lt;/strong&gt; — Mamba's O(1) inference enables streaming use cases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model tiering evolves&lt;/strong&gt; — hybrid for bulk processing, Transformer for precision&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;The AI architecture landscape is evolving fast. Transformers gave us the foundation. Mamba showed us there's a better way to handle long sequences. And hybrids are proving you don't have to choose — you can have both.&lt;/p&gt;

&lt;p&gt;The future isn't "Transformer vs Mamba." It's &lt;strong&gt;"Transformer AND Mamba, used where each excels."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're an engineer working with AI, now is a great time to understand these architectures. The next generation of models you'll be using — and maybe building on — will likely be hybrids.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;If you found this useful, drop a like or a comment. I'm happy to go deeper on any section — the attention math, the SSM discretization, or the MoE routing if there's interest.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm Himanshu — an AI-augmented full-stack developer exploring how these architectures change the way we build software. Follow me for more deep dives on AI engineering.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>deeplearning</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Have You Wondered How Websites Show the Download Button According to Your Operating System?</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Mon, 06 Oct 2025 18:30:31 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/have-you-wondered-how-websites-show-the-download-button-according-to-your-operating-system-d2</link>
      <guid>https://dev.to/himanshusinghtomar/have-you-wondered-how-websites-show-the-download-button-according-to-your-operating-system-d2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Like when you visit a website, and it already knows you’re on Windows or macOS — magic, right?&lt;/em&gt;&lt;br&gt;
Let’s decode that small but clever trick together.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  💭 The Curiosity
&lt;/h2&gt;

&lt;p&gt;A few days ago, while visiting popular websites like &lt;strong&gt;VS Code&lt;/strong&gt;, &lt;strong&gt;Zoom&lt;/strong&gt;, or &lt;strong&gt;Slack&lt;/strong&gt;, I noticed something fascinating.&lt;br&gt;
Every time I opened them, the &lt;strong&gt;download button automatically matched my OS&lt;/strong&gt; —&lt;br&gt;
“Download for macOS” on my Mac, and “Download for Windows” when I switched to my PC.&lt;/p&gt;

&lt;p&gt;That made me wonder — &lt;em&gt;how does a website even know what operating system I’m using?&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ The Hidden Magic Behind It
&lt;/h2&gt;

&lt;p&gt;Turns out, your browser quietly sends a small piece of information called a &lt;strong&gt;User Agent&lt;/strong&gt; every time you open a website.&lt;br&gt;
It’s like a self-introduction that tells the website who you are and what device you’re on.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0 Safari/537.36”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From that single line, the website can identify if you’re on &lt;strong&gt;Windows&lt;/strong&gt;, &lt;strong&gt;macOS&lt;/strong&gt;, &lt;strong&gt;Linux&lt;/strong&gt;, or even &lt;strong&gt;Android/iOS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Once it knows that, it can personalize what you see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show the right &lt;strong&gt;download button&lt;/strong&gt; for your OS&lt;/li&gt;
&lt;li&gt;Change the &lt;strong&gt;UI elements&lt;/strong&gt; or &lt;strong&gt;icons&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Load &lt;strong&gt;platform-specific instructions&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌍 Where You’ve Seen It
&lt;/h2&gt;

&lt;p&gt;This isn’t just a small trick — it’s used by almost every major platform you visit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zoom&lt;/strong&gt;, &lt;strong&gt;Discord&lt;/strong&gt;, and &lt;strong&gt;Slack&lt;/strong&gt;: Show OS-based download buttons.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spotify&lt;/strong&gt; and &lt;strong&gt;VS Code&lt;/strong&gt;: Automatically serve installers that match your operating system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web apps&lt;/strong&gt;: Adjust UI layouts based on your device type or platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These small adjustments make users feel like the site was built just for them.&lt;/p&gt;




&lt;h2&gt;
  
  
  💬 My Thought
&lt;/h2&gt;

&lt;p&gt;Imagine this — someone opens your website from a &lt;strong&gt;Windows&lt;/strong&gt; laptop and sees a calm, blue &lt;strong&gt;Windows-inspired background&lt;/strong&gt;.&lt;br&gt;
Another person opens it on a &lt;strong&gt;Mac&lt;/strong&gt; and sees a sleek, minimalist &lt;strong&gt;macOS-style wallpaper&lt;/strong&gt;.&lt;br&gt;
And maybe someone on &lt;strong&gt;Linux&lt;/strong&gt; gets a bold, terminal-themed design.&lt;/p&gt;

&lt;p&gt;How cool does that sound? 😄&lt;br&gt;
Just by detecting the OS, your website starts to feel more personal — like it actually &lt;em&gt;knows&lt;/em&gt; its visitors.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>ai</category>
    </item>
    <item>
      <title>Scalable React Application Architecture Guide</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Wed, 02 Jul 2025 07:11:59 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/scalable-react-application-architecture-guide-43j7</link>
      <guid>https://dev.to/himanshusinghtomar/scalable-react-application-architecture-guide-43j7</guid>
      <description>&lt;h2&gt;
  
  
  🧩 1. Project Structure &amp;amp; Organizing Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feature-based directory layout&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
src/
├── features/         # Feature-specific logic
├── components/       # Reusable presentational components
├── hooks/            # Custom hooks
├── services/         # API clients and side-effects
├── store/            # Global state (Redux/Zustand/Recoil)
├── utils/            # Pure utility functions
└── App.tsx / index.tsx

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Barrel exports&lt;/strong&gt;:
Use &lt;code&gt;index.ts&lt;/code&gt; files inside folders to group and simplify imports.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🛠 2. Design Patterns &amp;amp; Component Architecture
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Container vs Presentational Components&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;Container: Handles state, API calls.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Presentational: Stateless UI component, receives props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hooks &amp;amp; Custom Hooks&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shared logic should go into custom hooks like &lt;code&gt;useAuth&lt;/code&gt;, &lt;code&gt;useForm&lt;/code&gt;, &lt;code&gt;useFetch&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Higher-Order Components (HOC)&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For reusable behaviors (e.g., logging, auth gating).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compound Components &amp;amp; Context&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable scoped, flexible UIs using parent-child coordination.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memoization&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;React.memo&lt;/code&gt;, &lt;code&gt;useMemo&lt;/code&gt;, &lt;code&gt;useCallback&lt;/code&gt; for performance.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🎯 3. State &amp;amp; Data Management
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global state management&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;Use Redux Toolkit, Recoil, Zustand, or Context API.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minimize global state. Keep UI-specific state local.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unidirectional data flow&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Actions → Reducers → State → Props → UI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Side-effect management&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;Redux Thunk&lt;/code&gt;, &lt;code&gt;Redux Saga&lt;/code&gt;, &lt;code&gt;React Query&lt;/code&gt;, or &lt;code&gt;SWR&lt;/code&gt; for async ops.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📡 4. API Layer &amp;amp; Services
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Service abstraction&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;Encapsulate all API calls in &lt;code&gt;/services&lt;/code&gt; using Axios/Fetch.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example:&lt;br&gt;
&lt;code&gt;&lt;/code&gt;&lt;code&gt;ts&lt;br&gt;
export const getUserProfile = () =&amp;gt; api.get('/user/profile');&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error &amp;amp; loading handling&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use React Query or loading/error state wrappers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication tokens&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prefer &lt;code&gt;HttpOnly&lt;/code&gt; cookies for secure auth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Abstract auth/session logic in dedicated services or hooks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧪 5. Code Quality &amp;amp; Testing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Linting&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;ESLint&lt;/code&gt;, &lt;code&gt;Prettier&lt;/code&gt;, and &lt;code&gt;Husky&lt;/code&gt; for commit-time lint checks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unit tests: Vitest/Jest + React Testing Library&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integration/E2E: Playwright or Cypress&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing strategy&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write tests for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pure functions (utils, services)&lt;/li&gt;
&lt;li&gt;Component rendering + behavior&lt;/li&gt;
&lt;li&gt;Hooks logic&lt;/li&gt;
&lt;li&gt;API handling&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🚀 6. Performance Optimization
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Code splitting&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lazy load route-based components using &lt;code&gt;React.lazy()&lt;/code&gt; and &lt;code&gt;Suspense&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memoization&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prevent re-renders with &lt;code&gt;React.memo&lt;/code&gt;, &lt;code&gt;useMemo&lt;/code&gt;, and &lt;code&gt;useCallback&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bundle analysis&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use tools like &lt;code&gt;webpack-bundle-analyzer&lt;/code&gt; or Vite plugins.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid over-rendering&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lift state only when necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Split complex components.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🔐 7. Security &amp;amp; Error Handling
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Error boundaries&lt;/strong&gt;:&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;ErrorBoundary&lt;/code&gt; components to catch rendering issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Global error handling&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrap API services to catch and standardize error handling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security practices&lt;/strong&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate all inputs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid XSS via sanitization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use secure cookies and &lt;code&gt;SameSite&lt;/code&gt; attributes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🛡️ 8. Bulletproof React Template (by alan2207)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Repo: &lt;a href="https://github.com/alan2207/bulletproof-react" rel="noopener noreferrer"&gt;github.com/alan2207/bulletproof-react&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Feature-first folder structure&lt;/li&gt;
&lt;li&gt;Modular state management (Redux Toolkit or Zustand)&lt;/li&gt;
&lt;li&gt;Centralized API abstraction&lt;/li&gt;
&lt;li&gt;Forms (React Hook Form + Zod)&lt;/li&gt;
&lt;li&gt;Routes split per feature&lt;/li&gt;
&lt;li&gt;Testing setup with Vitest, Testing Library, Playwright&lt;/li&gt;
&lt;li&gt;Styling with Tailwind/Shadcn UI&lt;/li&gt;
&lt;li&gt;Environment validation (Zod)&lt;/li&gt;
&lt;li&gt;Vite-based build pipeline&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🧭 Sample Folder Structure
&lt;/h2&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
src/
├── features/
│   └── auth/
│       ├── components/
│       ├── hooks/
│       ├── api/
│       └── AuthPage.tsx
├── components/
├── services/
├── hooks/
├── store/
├── routes/
├── utils/
├── App.tsx
└── main.tsx

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Final Checklist for Scalable React Apps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[x] Feature-based directory structure&lt;/li&gt;
&lt;li&gt;[x] Clear separation of concerns (logic vs UI)&lt;/li&gt;
&lt;li&gt;[x] Abstracted services and state&lt;/li&gt;
&lt;li&gt;[x] Custom hooks for shared logic&lt;/li&gt;
&lt;li&gt;[x] Error boundaries and global error handling&lt;/li&gt;
&lt;li&gt;[x] API and state decoupling&lt;/li&gt;
&lt;li&gt;[x] Secure token storage practices&lt;/li&gt;
&lt;li&gt;[x] CI-ready with linting, formatting, and testing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📚 References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.bacancytechnology.com/blog/react-architecture-patterns-and-best-practices" rel="noopener noreferrer"&gt;React Architecture Patterns – Bacancy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alan2207/bulletproof-react" rel="noopener noreferrer"&gt;Bulletproof React – GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/drruvari/building-scalable-react-applications-design-patterns-and-architecture-39a0"&gt;Scalable React App Design – Dev.to&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>EC2 Placement Groups: Optimizing Instance Placement for Performance and Availability</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Tue, 06 May 2025 19:12:26 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/ec2-placement-groups-optimizing-instance-placement-for-performance-and-availability-5hhi</link>
      <guid>https://dev.to/himanshusinghtomar/ec2-placement-groups-optimizing-instance-placement-for-performance-and-availability-5hhi</guid>
      <description>&lt;p&gt;Placement groups in Amazon EC2 allow you to influence how your instances are positioned relative to each other in the underlying AWS infrastructure. By strategically organizing your instances, you can optimize your applications for specific workload requirements such as high network throughput, low latency, or high availability.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are EC2 Placement Groups?
&lt;/h2&gt;

&lt;p&gt;A placement group is a logical grouping of EC2 instances that influences how these instances are placed on the underlying hardware infrastructure. Placement groups help you meet specific performance, availability, or failure tolerance requirements by controlling how instances are distributed across different hardware.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Placement Groups
&lt;/h2&gt;

&lt;p&gt;AWS offers three distinct placement group strategies, each designed for different use cases:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Cluster Placement Groups
&lt;/h3&gt;

&lt;p&gt;Cluster placement groups pack instances close together inside an Availability Zone, providing the lowest-latency network performance possible between instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instances are placed in the same high-bisection bandwidth segment of the network&lt;/li&gt;
&lt;li&gt;Provides the lowest latency and highest packet-per-second network performance&lt;/li&gt;
&lt;li&gt;All instances are placed in a single Availability Zone&lt;/li&gt;
&lt;li&gt;Limited to a single Availability Zone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High Performance Computing (HPC) applications&lt;/li&gt;
&lt;li&gt;Tightly-coupled node-to-node communication&lt;/li&gt;
&lt;li&gt;Applications requiring extremely low-latency networking&lt;/li&gt;
&lt;li&gt;Big data jobs requiring fast completion times&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Spread Placement Groups
&lt;/h3&gt;

&lt;p&gt;Spread placement groups strictly place instances on distinct underlying hardware to reduce correlated failures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each instance runs on different physical hardware&lt;/li&gt;
&lt;li&gt;Maximum of 7 instances per Availability Zone in each spread placement group&lt;/li&gt;
&lt;li&gt;Can span multiple Availability Zones in a region&lt;/li&gt;
&lt;li&gt;Provides instance-level failure isolation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applications that require high availability&lt;/li&gt;
&lt;li&gt;Critical applications where instances should be isolated from each other&lt;/li&gt;
&lt;li&gt;Applications where failure of a single instance should not affect other instances&lt;/li&gt;
&lt;li&gt;Small applications needing maximum reliability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Partition Placement Groups
&lt;/h3&gt;

&lt;p&gt;Partition placement groups distribute instances across logical partitions, ensuring that instances in one partition do not share underlying hardware with instances in other partitions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Divides each group into logical segments called partitions (up to 7 per AZ)&lt;/li&gt;
&lt;li&gt;Each partition has its own set of racks with independent network and power&lt;/li&gt;
&lt;li&gt;Can span multiple Availability Zones in a region&lt;/li&gt;
&lt;li&gt;Hundreds of instances per placement group&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large distributed and replicated workloads&lt;/li&gt;
&lt;li&gt;HDFS, HBase, and Cassandra deployments&lt;/li&gt;
&lt;li&gt;Applications deployed across multiple instances that need topology awareness&lt;/li&gt;
&lt;li&gt;Applications that need to isolate potential hardware failures to a subset of the system&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Placement Group Limitations and Rules
&lt;/h2&gt;

&lt;p&gt;Understanding these limitations will help you plan your deployment effectively:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can't merge placement groups&lt;/li&gt;
&lt;li&gt;An instance can only be launched in one placement group at a time&lt;/li&gt;
&lt;li&gt;Reserved Instances provide a capacity reservation for EC2 instances in a specific Availability Zone, but don't guarantee placement group capacity&lt;/li&gt;
&lt;li&gt;On-Demand Capacity Reservation can be used with placement groups to reserve capacity&lt;/li&gt;
&lt;li&gt;Existing instances cannot be moved into a placement group; you must create a new instance or snapshot an existing instance and launch a new one&lt;/li&gt;
&lt;li&gt;Not all instance types are supported in all placement group types&lt;/li&gt;
&lt;li&gt;AWS has a soft limit on the number of placement groups per region (default is 500)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When to Use Each Placement Group Type
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Placement Group Type&lt;/th&gt;
&lt;th&gt;Use When You Need&lt;/th&gt;
&lt;th&gt;Avoid When&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cluster&lt;/td&gt;
&lt;td&gt;Highest network performance, lowest latency&lt;/td&gt;
&lt;td&gt;High availability across AZs is required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spread&lt;/td&gt;
&lt;td&gt;Maximum instance failure isolation&lt;/td&gt;
&lt;td&gt;You need more than 7 instances per AZ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Partition&lt;/td&gt;
&lt;td&gt;Balance between performance and partial fault tolerance&lt;/td&gt;
&lt;td&gt;Complete instance isolation is required&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Step-by-Step: Creating and Using Placement Groups
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating a Placement Group
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using the AWS Management Console
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open the EC2 Console&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign in to the AWS Management Console&lt;/li&gt;
&lt;li&gt;Navigate to the EC2 dashboard&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Access Placement Groups&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the navigation pane, choose &lt;strong&gt;Placement Groups&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create placement group&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure the Placement Group&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter a name for your placement group&lt;/li&gt;
&lt;li&gt;Choose the placement strategy (Cluster, Spread, or Partition)&lt;/li&gt;
&lt;li&gt;For Partition placement groups, optionally specify the number of partitions&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Create group&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using the AWS CLI
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a cluster placement group&lt;/span&gt;
aws ec2 create-placement-group &lt;span class="nt"&gt;--group-name&lt;/span&gt; MyClusterGroup &lt;span class="nt"&gt;--strategy&lt;/span&gt; cluster

&lt;span class="c"&gt;# Create a spread placement group&lt;/span&gt;
aws ec2 create-placement-group &lt;span class="nt"&gt;--group-name&lt;/span&gt; MySpreadGroup &lt;span class="nt"&gt;--strategy&lt;/span&gt; spread

&lt;span class="c"&gt;# Create a partition placement group with 5 partitions&lt;/span&gt;
aws ec2 create-placement-group &lt;span class="nt"&gt;--group-name&lt;/span&gt; MyPartitionGroup &lt;span class="nt"&gt;--strategy&lt;/span&gt; partition &lt;span class="nt"&gt;--partition-count&lt;/span&gt; 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Launching Instances in a Placement Group
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using the AWS Management Console
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start the Instance Launch Process&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the EC2 dashboard&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Launch Instance&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Select an AMI and Instance Type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose an AMI&lt;/li&gt;
&lt;li&gt;Select an instance type compatible with placement groups&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Instance Details&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On the "Configure Instance" page, find the "Placement group" section&lt;/li&gt;
&lt;li&gt;Select "Add instance to placement group"&lt;/li&gt;
&lt;li&gt;Choose your placement group from the dropdown&lt;/li&gt;
&lt;li&gt;For partition placement groups, optionally select a specific partition&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Complete the Launch Process&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configure storage, security groups, and other settings as needed&lt;/li&gt;
&lt;li&gt;Review and launch your instance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using the AWS CLI
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Launch an instance in a cluster placement group&lt;/span&gt;
aws ec2 run-instances &lt;span class="nt"&gt;--image-id&lt;/span&gt; ami-0abcdef1234567890 &lt;span class="nt"&gt;--instance-type&lt;/span&gt; c5.large &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--placement&lt;/span&gt; &lt;span class="s2"&gt;"GroupName=MyClusterGroup"&lt;/span&gt; &lt;span class="nt"&gt;--count&lt;/span&gt; 1

&lt;span class="c"&gt;# Launch an instance in a specific partition of a partition placement group&lt;/span&gt;
aws ec2 run-instances &lt;span class="nt"&gt;--image-id&lt;/span&gt; ami-0abcdef1234567890 &lt;span class="nt"&gt;--instance-type&lt;/span&gt; r5.large &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--placement&lt;/span&gt; &lt;span class="s2"&gt;"GroupName=MyPartitionGroup,PartitionNumber=3"&lt;/span&gt; &lt;span class="nt"&gt;--count&lt;/span&gt; 1

&lt;span class="c"&gt;# Launch an instance in a spread placement group&lt;/span&gt;
aws ec2 run-instances &lt;span class="nt"&gt;--image-id&lt;/span&gt; ami-0abcdef1234567890 &lt;span class="nt"&gt;--instance-type&lt;/span&gt; m5.large &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--placement&lt;/span&gt; &lt;span class="s2"&gt;"GroupName=MySpreadGroup"&lt;/span&gt; &lt;span class="nt"&gt;--count&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Viewing Your Placement Groups
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using the AWS Management Console
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the EC2 dashboard&lt;/li&gt;
&lt;li&gt;In the navigation pane, choose &lt;strong&gt;Placement Groups&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;View your placement groups and their details&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using the AWS CLI
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# List all placement groups&lt;/span&gt;
aws ec2 describe-placement-groups

&lt;span class="c"&gt;# Get details about a specific placement group&lt;/span&gt;
aws ec2 describe-placement-groups &lt;span class="nt"&gt;--group-names&lt;/span&gt; MyClusterGroup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deleting a Placement Group
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Using the AWS Management Console
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to the EC2 dashboard&lt;/li&gt;
&lt;li&gt;In the navigation pane, choose &lt;strong&gt;Placement Groups&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Select the placement group to delete&lt;/li&gt;
&lt;li&gt;Choose &lt;strong&gt;Actions&lt;/strong&gt;, then &lt;strong&gt;Delete placement group&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Confirm the deletion&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using the AWS CLI
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# First terminate all instances in the placement group, then delete it&lt;/span&gt;
aws ec2 delete-placement-group &lt;span class="nt"&gt;--group-name&lt;/span&gt; MyClusterGroup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Best Practices for EC2 Placement Groups
&lt;/h2&gt;

&lt;h3&gt;
  
  
  General Best Practices
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Launch instances with a single request&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launch all instances within a placement group in a single request to increase the likelihood of fulfilling the placement requirements&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use the same instance type&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the same instance type for all instances in a cluster placement group to ensure consistent network performance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Plan for capacity&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reserve capacity in advance for placement groups, especially for cluster placement groups&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Consider enhanced networking&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use instances that support Enhanced Networking for better performance, especially in cluster placement groups&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Cluster Placement Group Best Practices
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use a homogeneous instance fleet&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launch the same instance type and size for optimal network performance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Launch all instances at once&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This maximizes the chances of getting the required capacity&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Consider instance limits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be aware of your account's instance limits, as cluster placement groups can require substantial resources in a single AZ&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Spread Placement Group Best Practices
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use for critical applications&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy mission-critical applications where each instance must be isolated from failure of other instances&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Combine with multiple AZs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spread across multiple AZs for maximum availability&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Plan around the 7-instance limit&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Design your architecture to work within the 7-instance-per-AZ limitation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Partition Placement Group Best Practices
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use topology awareness&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make your applications topology-aware to optimize communication between partitions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Balance workloads across partitions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Distribute workloads evenly across partitions for optimal performance&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use partition information&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applications can access partition information via instance metadata to make intelligent data replication decisions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Real-World Scenarios and Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Scenario 1: High-Performance Computing Cluster
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Requirement:&lt;/strong&gt; Create a high-performance cluster for scientific computing with minimal network latency.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Create a cluster placement group&lt;/li&gt;
&lt;li&gt;Launch all compute nodes using the same high-performance instance type (e.g., c5n.18xlarge)&lt;/li&gt;
&lt;li&gt;Use EFA-enabled instances for MPI workloads&lt;/li&gt;
&lt;li&gt;Configure a single request to launch all instances simultaneously&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Scenario 2: Highly Available Web Application
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Requirement:&lt;/strong&gt; Deploy a web application with maximum availability and failure isolation.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Create a spread placement group spanning multiple AZs&lt;/li&gt;
&lt;li&gt;Launch up to 7 instances per AZ in the spread placement group&lt;/li&gt;
&lt;li&gt;Configure an Application Load Balancer to distribute traffic&lt;/li&gt;
&lt;li&gt;Set up Auto Scaling with the placement group for automatic recovery&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Scenario 3: Large Distributed Database
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Requirement:&lt;/strong&gt; Deploy a large distributed database system (like Apache Cassandra) with fault tolerance.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Create a partition placement group with 5 partitions&lt;/li&gt;
&lt;li&gt;Launch your database nodes across the partitions&lt;/li&gt;
&lt;li&gt;Configure your database to be topology-aware&lt;/li&gt;
&lt;li&gt;Ensure replication factors consider partition boundaries&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Monitoring Placement Groups
&lt;/h2&gt;

&lt;p&gt;AWS provides several tools to monitor the health and performance of your instances in placement groups:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CloudWatch Metrics&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monitor network performance metrics to verify you're getting the expected benefits from your placement strategy&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;EC2 Status Checks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep track of instance status checks to quickly identify hardware issues&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;AWS Trusted Advisor&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get recommendations for optimizing your EC2 placement groups&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;AWS Health Dashboard&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be alerted about potential hardware failures that might affect your placement groups&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;EC2 placement groups are a powerful tool for optimizing the placement of your instances to meet specific performance, availability, and fault tolerance requirements. By understanding the characteristics of each placement group type and following the best practices outlined in this guide, you can design EC2 deployments that better meet your application's unique requirements.&lt;/p&gt;

&lt;p&gt;Whether you need the lowest-latency network performance for HPC workloads, maximum instance isolation for critical applications, or a balance between performance and fault tolerance for distributed systems, EC2 placement groups provide the controls you need to implement your ideal infrastructure architecture in AWS.&lt;/p&gt;

&lt;p&gt;Remember that placement groups are a free feature of Amazon EC2, so there's no additional cost to using them—making them an essential tool in your AWS optimization toolkit.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding ENI (Elastic Network Interface) in EC2</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Tue, 06 May 2025 18:31:57 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/understanding-eni-elastic-network-interface-in-ec2-1f8i</link>
      <guid>https://dev.to/himanshusinghtomar/understanding-eni-elastic-network-interface-in-ec2-1f8i</guid>
      <description>&lt;p&gt;Elastic Network Interfaces (ENIs) are a fundamental networking component in Amazon EC2 that provide enhanced connectivity, security, and flexibility for your cloud infrastructure. This article explores ENIs in depth, covering their key features, use cases, and best practices for implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an Elastic Network Interface (ENI)?
&lt;/h2&gt;

&lt;p&gt;An Elastic Network Interface (ENI) is a virtual network interface that you can attach to an EC2 instance in a VPC. Think of an ENI as a virtual network card that provides connectivity between your EC2 instances and other resources within your AWS environment.&lt;/p&gt;

&lt;p&gt;Each ENI has the following attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A primary private IPv4 address&lt;/li&gt;
&lt;li&gt;One or more secondary IPv4 addresses&lt;/li&gt;
&lt;li&gt;One Elastic IP address per private IPv4 address&lt;/li&gt;
&lt;li&gt;One public IPv4 address&lt;/li&gt;
&lt;li&gt;One or more IPv6 addresses&lt;/li&gt;
&lt;li&gt;One or more security groups&lt;/li&gt;
&lt;li&gt;A MAC address&lt;/li&gt;
&lt;li&gt;A source/destination check flag&lt;/li&gt;
&lt;li&gt;A description&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Primary vs. Secondary Network Interfaces
&lt;/h2&gt;

&lt;p&gt;Every EC2 instance has a default primary network interface (eth0) that cannot be detached. You can create and attach additional secondary network interfaces to your instances, with limitations based on instance type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Benefits of ENIs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Enhanced Network Architecture
&lt;/h3&gt;

&lt;p&gt;ENIs allow you to create complex network topologies such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-homed instances with workloads/roles on distinct subnets&lt;/li&gt;
&lt;li&gt;Low-budget, high-availability solutions&lt;/li&gt;
&lt;li&gt;Network and security appliance deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Network Traffic Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create management networks separate from application traffic&lt;/li&gt;
&lt;li&gt;Use network and security appliances in your VPC&lt;/li&gt;
&lt;li&gt;Create dual-homed instances with workloads/roles on distinct subnets&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  High Availability
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ENIs can be detached from one instance and attached to another&lt;/li&gt;
&lt;li&gt;IP addresses stay with the ENI during moves&lt;/li&gt;
&lt;li&gt;Facilitates fast failover scenarios&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Use Cases for ENIs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Multi-IP Applications
&lt;/h3&gt;

&lt;p&gt;Applications that require multiple IP addresses can benefit from ENIs with secondary IP addresses. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web servers hosting multiple domains with separate SSL certificates&lt;/li&gt;
&lt;li&gt;Application servers that need to communicate on multiple subnets&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Network Security Solutions
&lt;/h3&gt;

&lt;p&gt;Security appliances like firewalls and intrusion detection systems often require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One interface for management traffic&lt;/li&gt;
&lt;li&gt;One or more interfaces for data traffic inspection&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Workload Isolation
&lt;/h3&gt;

&lt;p&gt;Different applications on the same instance can use different network interfaces with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Distinct security groups&lt;/li&gt;
&lt;li&gt;Separate subnets&lt;/li&gt;
&lt;li&gt;Individual routing policies&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. High Availability Scenarios
&lt;/h3&gt;

&lt;p&gt;When implementing high availability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pre-configure a standby instance with ENIs ready&lt;/li&gt;
&lt;li&gt;During failover, detach ENIs from failed instance&lt;/li&gt;
&lt;li&gt;Attach ENIs to standby instance&lt;/li&gt;
&lt;li&gt;IP addresses remain consistent, minimizing DNS propagation delays&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Technical Specifications and Limitations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Instance Type Considerations
&lt;/h3&gt;

&lt;p&gt;The number of ENIs and IP addresses you can attach varies by instance type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Smaller instances (t2.micro): 2-3 ENIs, 2-4 IPs per interface&lt;/li&gt;
&lt;li&gt;Larger instances (c5.24xlarge): 15+ ENIs, 50+ IPs per interface&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Performance Considerations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ENIs have bandwidth limits based on the instance type&lt;/li&gt;
&lt;li&gt;Traffic between ENIs on the same instance stays on the host (no physical network transfer)&lt;/li&gt;
&lt;li&gt;Enhanced Networking instances provide higher performance for network-intensive workloads&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices for ENI Management
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Security Group Configuration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Assign different security groups to different ENIs based on their function&lt;/li&gt;
&lt;li&gt;Keep management interfaces in restricted security groups&lt;/li&gt;
&lt;li&gt;Apply least privilege principles to each interface&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. IP Address Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Plan your IP addressing scheme carefully&lt;/li&gt;
&lt;li&gt;Consider using secondary IP addresses rather than multiple ENIs when possible&lt;/li&gt;
&lt;li&gt;Use DHCP option sets to configure DNS settings&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Monitoring and Maintenance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tag ENIs appropriately for better resource management&lt;/li&gt;
&lt;li&gt;Monitor network traffic per interface using CloudWatch&lt;/li&gt;
&lt;li&gt;Regularly review security groups and network ACLs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Automation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use AWS CLI or SDKs to automate ENI attachment/detachment&lt;/li&gt;
&lt;li&gt;Implement auto-recovery scripts for failover scenarios&lt;/li&gt;
&lt;li&gt;Consider integration with AWS Lambda for event-driven network changes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Enhanced Networking Options: ENA vs EFA vs ENA with EFA
&lt;/h3&gt;

&lt;p&gt;AWS offers several networking technologies to improve performance beyond standard ENI capabilities:&lt;/p&gt;

&lt;h2&gt;
  
  
  Elastic Network Adapter (ENA)
&lt;/h2&gt;

&lt;p&gt;ENA is AWS's primary enhanced networking technology that provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher bandwidth (up to 100 Gbps for supported instance types)&lt;/li&gt;
&lt;li&gt;Higher packet per second (PPS) performance&lt;/li&gt;
&lt;li&gt;Consistently lower inter-instance latencies&lt;/li&gt;
&lt;li&gt;Lower CPU utilization for networking tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most modern EC2 instance types support ENA by default. ENA uses single root I/O virtualization (SR-IOV) to provide high-performance networking capabilities, significantly improving performance compared to traditional virtualized network interfaces.&lt;/p&gt;

&lt;p&gt;Key benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Up to 100 Gbps of network bandwidth&lt;/li&gt;
&lt;li&gt;Lower latency and jitter&lt;/li&gt;
&lt;li&gt;Higher packets per second (PPS)&lt;/li&gt;
&lt;li&gt;Hardware-based offloading for network functions&lt;/li&gt;
&lt;li&gt;Automatic configuration on supported AMIs
Suitable for:&lt;/li&gt;
&lt;li&gt;General network-intensive applications&lt;/li&gt;
&lt;li&gt;Applications requiring consistent network performance&lt;/li&gt;
&lt;li&gt;Workloads with high throughput requirements&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Elastic Fabric Adapter (EFA)
&lt;/h2&gt;

&lt;p&gt;EFA is a network interface for EC2 instances designed specifically for high-performance computing (HPC) and machine learning applications that require lower latency and higher throughput than what's possible with traditional TCP transport.&lt;/p&gt;

&lt;p&gt;Key features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS-bypass capability allows applications to communicate directly with the network interface&lt;/li&gt;
&lt;li&gt;Custom-built reliable transport protocol that bypasses the operating system kernel&lt;/li&gt;
&lt;li&gt;Support for industry-standard libfabric API&lt;/li&gt;
&lt;li&gt;Compatible with existing Message Passing Interface (MPI) applications
Suitable for:&lt;/li&gt;
&lt;li&gt;High Performance Computing (HPC) applications&lt;/li&gt;
&lt;li&gt;Machine Learning distributed training&lt;/li&gt;
&lt;li&gt;Applications using MPI (Message Passing Interface)&lt;/li&gt;
&lt;li&gt;Computational fluid dynamics, weather modeling, and similar workloads&lt;/li&gt;
&lt;li&gt;Tightly coupled workloads requiring low-latency node-to-node communication&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ENA with EFA
&lt;/h2&gt;

&lt;p&gt;Some EC2 instances support both ENA and EFA simultaneously, offering the best of both worlds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ENA provides high-bandwidth TCP/IP performance for general network traffic&lt;/li&gt;
&lt;li&gt;EFA provides ultra-low latency OS-bypass capabilities for specialized HPC workloads
Benefits of combined usage:&lt;/li&gt;
&lt;li&gt;Maintain compatibility with standard networking applications via 
ENA&lt;/li&gt;
&lt;li&gt;Utilize EFA for specific MPI or HPC workloads requiring the lowest possible latency&lt;/li&gt;
&lt;li&gt;No need to choose between networking technologies – use both as needed
Configuration considerations:&lt;/li&gt;
&lt;li&gt;EFA requires specific security group configurations to allow all traffic between instances in the security group&lt;/li&gt;
&lt;li&gt;EFA-enabled ENIs require specific placement in the correct subnets for cluster communication&lt;/li&gt;
&lt;li&gt;Applications must be built with EFA-aware libraries to leverage OS-bypass capabilities&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Practical Implementation Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1: Basic Multi-Interface Configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new ENI in a specific subnet&lt;/span&gt;
aws ec2 create-network-interface &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--subnet-id&lt;/span&gt; subnet-abcd1234 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--description&lt;/span&gt; &lt;span class="s2"&gt;"Secondary ENI"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--groups&lt;/span&gt; sg-abcd1234 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--private-ip-address&lt;/span&gt; 10.0.1.100

&lt;span class="c"&gt;# Attach the ENI to an instance&lt;/span&gt;
aws ec2 attach-network-interface &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--network-interface-id&lt;/span&gt; eni-abcd1234 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--instance-id&lt;/span&gt; i-1234567890abcdef0 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--device-index&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2: High Availability Setup
&lt;/h3&gt;

&lt;p&gt;In a high availability scenario, you might prepare standby instances with scripts that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detect primary instance failure&lt;/li&gt;
&lt;li&gt;Detach ENIs from failed instance&lt;/li&gt;
&lt;li&gt;Attach ENIs to standby instance&lt;/li&gt;
&lt;li&gt;Update route tables or DNS records if necessary&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Potential Challenges and Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Challenge 1: IP Address Exhaustion
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Use secondary IP addresses on existing ENIs rather than creating new ENIs when possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 2: Route Table Management
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Create scripts or use AWS Lambda to update route tables when ENIs are moved between instances.&lt;/p&gt;

&lt;h3&gt;
  
  
  Challenge 3: DNS Propagation Delays
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Use Elastic IPs with ENIs and implement application-level health checks.&lt;/p&gt;

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

&lt;p&gt;Elastic Network Interfaces provide powerful networking capabilities for EC2 instances, enabling complex network architectures, enhanced security configurations, and high availability solutions. By understanding ENI capabilities and following best practices, you can design robust and flexible cloud infrastructure that meets your organization's specific networking requirements.&lt;/p&gt;

&lt;p&gt;Whether you're implementing multi-tier applications, security appliances, or high availability solutions, ENIs offer the flexibility and control needed to optimize your AWS network infrastructure.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>awschallenge</category>
      <category>bash</category>
      <category>awsbigdata</category>
    </item>
    <item>
      <title>AWS EC2 Instance Types</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Sat, 03 May 2025 06:46:50 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/aws-ec2-instance-types-16c0</link>
      <guid>https://dev.to/himanshusinghtomar/aws-ec2-instance-types-16c0</guid>
      <description>&lt;p&gt;Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Each instance type offers varying combinations of CPU, memory, storage, and networking capacity, giving you the flexibility to choose the appropriate mix of resources for your applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. General Purpose Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Balanced compute, memory, and networking resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;T Series (T2, T3, T3a, T4g):&lt;/strong&gt; Burstable performance for low to moderate CPU usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;M Series (M4, M5, M5a, M5n, M5zn, M6g, M6i, M6a, M6in, M7g, M7i, M7a, M7i-flex, M8g):&lt;/strong&gt; Balanced resources for a broad range of workloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Web and application servers&lt;/li&gt;
&lt;li&gt;Development and test environments&lt;/li&gt;
&lt;li&gt;Microservices&lt;/li&gt;
&lt;li&gt;Small and medium databases&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Compute Optimized Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Ideal for compute-bound applications that benefit from high-performance processors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C Series (C4, C5, C5a, C5n, C6g, C6i, C6a, C6in, C7g, C7i):&lt;/strong&gt; High-performance processors with a high ratio of compute to memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-performance web servers&lt;/li&gt;
&lt;li&gt;Scientific modeling and batch processing&lt;/li&gt;
&lt;li&gt;Machine learning inference&lt;/li&gt;
&lt;li&gt;Dedicated gaming servers&lt;/li&gt;
&lt;li&gt;Media transcoding&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Memory Optimized Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Designed to deliver fast performance for workloads that process large data sets in memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;R Series (R4, R5, R5a, R5n, R6g, R6i, R6a, R6in, R7g, R7i):&lt;/strong&gt; High memory-to-CPU ratio.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;X Series (X1, X1e, X2gd, X2idn, X2iedn):&lt;/strong&gt; High memory instances for in-memory databases and real-time big data analytics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Z Series (z1d):&lt;/strong&gt; High compute capacity and high memory footprint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High-performance databases&lt;/li&gt;
&lt;li&gt;In-memory caches (e.g., Redis, Memcached)&lt;/li&gt;
&lt;li&gt;Real-time big data analytics&lt;/li&gt;
&lt;li&gt;SAP HANA&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Storage Optimized Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Designed for workloads requiring high, sequential read and write access to large data sets on local storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;I Series (I3, I3en, I4i):&lt;/strong&gt; High IOPS storage optimized for low latency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D Series (D2, D3, D3en):&lt;/strong&gt; Dense HDD storage for data warehousing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;H Series (H1):&lt;/strong&gt; High disk throughput for big data workloads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NoSQL databases (e.g., Cassandra, MongoDB)&lt;/li&gt;
&lt;li&gt;Data warehousing&lt;/li&gt;
&lt;li&gt;Distributed file systems&lt;/li&gt;
&lt;li&gt;Hadoop distributed computing([Medium][1], [Amazon Web Services, Inc.][2])&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Accelerated Computing Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Utilize hardware accelerators for functions like floating-point number calculations, graphics processing, or data pattern matching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;P Series (P2, P3, P4, P4d):&lt;/strong&gt; GPU instances for machine learning and high-performance computing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inf Series (Inf1):&lt;/strong&gt; High-performance ML inference.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trn Series (Trn1):&lt;/strong&gt; Train ML models with high throughput.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;F Series (F1):&lt;/strong&gt; Field programmable gate arrays (FPGAs) for custom hardware acceleration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;G Series (G3, G4, G5):&lt;/strong&gt; Graphics-intensive applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Machine learning training and inference&lt;/li&gt;
&lt;li&gt;High-performance computing&lt;/li&gt;
&lt;li&gt;Video transcoding&lt;/li&gt;
&lt;li&gt;Real-time graphics rendering([handbook.vantage.sh][3])&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. High Performance Computing (HPC) Instances
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Purpose-built to offer the best price performance for running high-performance computing workloads at scale on AWS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instance Families:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HPC Series (Hpc6id, Hpc6a):&lt;/strong&gt; Optimized for tightly coupled, compute-intensive applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use Cases:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Computational fluid dynamics&lt;/li&gt;
&lt;li&gt;Finite element analysis&lt;/li&gt;
&lt;li&gt;Seismic processing&lt;/li&gt;
&lt;li&gt;Structural simulation&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Instance Features
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Key Features Across Instance Types:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Processor Options:&lt;/strong&gt; Intel Xeon, AMD EPYC, AWS Graviton processors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking:&lt;/strong&gt; Enhanced Networking with up to 200 Gbps of network bandwidth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage:&lt;/strong&gt; EBS-optimized instances with high throughput.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Support for always-on memory encryption using Intel Total Memory Encryption (TME).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Elastic Fabric Adapter (EFA):&lt;/strong&gt; Support for EFA on select instances for low-latency, high-bandwidth networking.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Choosing the Right Instance Type
&lt;/h2&gt;

&lt;p&gt;When selecting an EC2 instance type, consider the following factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Workload Requirements:&lt;/strong&gt; Determine if your application is compute, memory, storage, or network intensive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Needs:&lt;/strong&gt; Assess the required CPU, memory, storage, and networking performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost Optimization:&lt;/strong&gt; Balance performance needs with budget constraints.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Ensure the instance type supports your scalability requirements.([handbook.vantage.sh][4])&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  EC2 Pricing and Cost Optimization
&lt;/h2&gt;

&lt;p&gt;Understanding EC2 pricing models is crucial for cost-effective cloud usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pricing Models:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;On-Demand:&lt;/strong&gt; Pay for compute capacity by the hour or second with no long-term commitments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reserved Instances:&lt;/strong&gt; Commit to a one- or three-year term for significant discounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Savings Plans:&lt;/strong&gt; Flexible pricing model offering up to 72% savings over On-Demand pricing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spot Instances:&lt;/strong&gt; Bid on spare AWS EC2 computing capacity for up to 90% off the On-Demand price.([Amazon Web Services, Inc.][2], [Amnic][5], [Medium][1])&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cost Optimization Strategies:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rightsizing:&lt;/strong&gt; Regularly analyze and adjust instance types to match workload requirements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto Scaling:&lt;/strong&gt; Automatically adjust the number of instances to match demand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor Usage:&lt;/strong&gt; Use AWS Cost Explorer and other tools to monitor and analyze usage patterns.([handbook.vantage.sh][6], [Amnic][5])&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  EC2 Instance Pricing Comparison Tool
&lt;/h2&gt;

&lt;p&gt;For detailed pricing information and comparisons across all EC2 instance types and regions, refer to &lt;a href="https://instances.vantage.sh/" rel="noopener noreferrer"&gt;instances.vantage.sh&lt;/a&gt;. This tool provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comprehensive pricing details for On-Demand, Reserved, and Spot instances.&lt;/li&gt;
&lt;li&gt;Filtering options by region, instance type, and pricing model.&lt;/li&gt;
&lt;li&gt;Comparison features to evaluate different instance types side by side.&lt;/li&gt;
&lt;li&gt;Export capabilities for customized reports.([Medium][1], [docs.vantage.sh][7])&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Utilizing this tool can aid in making informed decisions to optimize both performance and cost.&lt;/p&gt;




&lt;p&gt;For more detailed information and the latest updates on EC2 instance types, refer to the official AWS documentation: &lt;a href="https://aws.amazon.com/ec2/instance-types/" rel="noopener noreferrer"&gt;Amazon EC2 Instance Types&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Deploying Sonatype Nexus on AWS EC2 using Terraform</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Sun, 13 Apr 2025 16:53:57 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/deploying-sonatype-nexus-on-aws-ec2-using-terraform-en6</link>
      <guid>https://dev.to/himanshusinghtomar/deploying-sonatype-nexus-on-aws-ec2-using-terraform-en6</guid>
      <description>&lt;p&gt;This guide will walk you through the steps to deploy a Nexus Repository Manager on an AWS EC2 instance using a Terraform script.&lt;/p&gt;




&lt;h2&gt;
  
  
  📁 Prerequisites
&lt;/h2&gt;

&lt;p&gt;Make sure you have the following installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.hashicorp.com/terraform/install" rel="noopener noreferrer"&gt;Terraform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html" rel="noopener noreferrer"&gt;AWS CLI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;An AWS account with credentials configured (via &lt;code&gt;aws configure&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;A valid SSH key pair created in your AWS account (needed to access EC2)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📄 Step-by-Step Instructions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. 🔑 Update Your Key Pair Name
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;aws_instance&lt;/code&gt; block, replace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;key_name&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"your-ssh-key"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with the actual name of your AWS EC2 key pair.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. 📦 Save the Terraform Code
&lt;/h3&gt;

&lt;p&gt;Save the entire provided Terraform code into a file named &lt;code&gt;main.tf&lt;/code&gt; in a directory of your choice.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. 📂 Initialize Terraform
&lt;/h3&gt;

&lt;p&gt;Open a terminal, navigate to the directory containing &lt;code&gt;[main.tf](https://github.com/Himanshusinghtomar/Sontype-Nexus/blob/main/sontype-nexus-aws-setup.tf)&lt;/code&gt;, and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. ✅ Validate the Configuration
&lt;/h3&gt;

&lt;p&gt;Make sure everything is correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform validate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  5. 🔍 Preview the Deployment
&lt;/h3&gt;

&lt;p&gt;Check what Terraform is going to create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  6. 🚀 Apply the Terraform Plan
&lt;/h3&gt;

&lt;p&gt;Create the resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type &lt;code&gt;yes&lt;/code&gt; when prompted to proceed.&lt;/p&gt;




&lt;h3&gt;
  
  
  7. 🌐 Access Nexus
&lt;/h3&gt;

&lt;p&gt;Once the infrastructure is deployed, Terraform will output the public IP of the EC2 instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nexus_public_ip = &amp;lt;YOUR_PUBLIC_IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then open your browser and access Nexus:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://&amp;lt;YOUR_PUBLIC_IP&amp;gt;:8081
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default admin password will be available in the instance at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cat /opt/sonatype-work/nexus3/admin.password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🧹 Optional: Destroy the Infrastructure
&lt;/h3&gt;

&lt;p&gt;To delete the resources when you're done:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Happy DevOpsing! 🎉&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting Up Nexus Repository on AWS EC2 with Terraform and Publishing a Custom Gradle Plugin</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Sun, 13 Apr 2025 16:42:30 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/setting-up-nexus-repository-on-aws-ec2-with-terraform-and-publishing-a-custom-gradle-plugin-p1</link>
      <guid>https://dev.to/himanshusinghtomar/setting-up-nexus-repository-on-aws-ec2-with-terraform-and-publishing-a-custom-gradle-plugin-p1</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction to Sonatype Nexus
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Sonatype Nexus?
&lt;/h3&gt;

&lt;p&gt;Sonatype Nexus is a powerful, open-source repository manager that allows organizations to store and manage software artifacts. It supports both internal and external repositories for various package formats such as Maven, npm, NuGet, Docker, and more. Nexus helps in managing and distributing binary artifacts, ensuring efficient version control and secure access to packages within an organization.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Why Use Nexus?
&lt;/h3&gt;

&lt;p&gt;Nexus Repository provides several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Centralized Artifact Management&lt;/strong&gt;: Nexus stores artifacts like libraries, dependencies, and Docker images, making them easy to share and reuse across different projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure Artifact Distribution&lt;/strong&gt;: It allows for secure access to artifacts through permissions and policies, preventing unauthorized access and ensuring the integrity of software artifacts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supports Multiple Formats&lt;/strong&gt;: Nexus supports different repository formats such as Maven, npm, Docker, etc., making it flexible and adaptable for various development environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with Build Systems&lt;/strong&gt;: Nexus can be integrated into CI/CD pipelines for automated artifact management and deployment.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Project Overview
&lt;/h2&gt;

&lt;p&gt;In this project, we automated the installation of Sonatype Nexus on an AWS EC2 instance using Terraform and demonstrated the publishing and usage of a custom Gradle plugin through Nexus.&lt;/p&gt;

&lt;p&gt;The project is divided into three major parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deploy Nexus via Terraform&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create and Publish a Custom Gradle Plugin to Nexus&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use the Published Plugin in a Spring Boot Backend Project&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  3. Deploying Nexus Using Terraform
&lt;/h2&gt;

&lt;p&gt;We created a Terraform configuration to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launch an EC2 instance&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Himanshusinghtomar/Sontype-Nexus/blob/main/setup-nexus.sh" rel="noopener noreferrer"&gt;Install Java and Nexus via a shell script&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Set up Nexus as a system service&lt;/li&gt;
&lt;li&gt;Open port &lt;code&gt;8081&lt;/code&gt; to access Nexus UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Terraform Files:&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;main.tf&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;  &lt;span class="c1"&gt;# Adjust region if necessary&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_instance"&lt;/span&gt; &lt;span class="s2"&gt;"nexus"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-0c55b159cbfafe1f0"&lt;/span&gt;  &lt;span class="c1"&gt;# Amazon Linux 2 AMI (adjust for your region)&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t3.medium"&lt;/span&gt;  &lt;span class="c1"&gt;# Adjust instance type as per your requirements&lt;/span&gt;
  &lt;span class="nx"&gt;key_name&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"your-ssh-key"&lt;/span&gt;  &lt;span class="c1"&gt;# Replace with your SSH key name&lt;/span&gt;

  &lt;span class="c1"&gt;# Security Group to allow access to port 8081 (Nexus)&lt;/span&gt;
  &lt;span class="nx"&gt;security_group&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nexus_sg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;

  &lt;span class="c1"&gt;# Instance metadata and user data to run the Nexus installation script&lt;/span&gt;
  &lt;span class="nx"&gt;user_data&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
              #!/bin/bash
              set -e
              # Update system and install Java
              sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y
              sudo apt install openjdk-8-jdk -y

              # Create nexus user
              sudo adduser --disabled-password --gecos "" nexus
              sudo usermod -aG sudo nexus

              # Download and install Nexus
              cd /opt
              sudo wget https://download.sonatype.com/nexus/3/nexus-3.70.4-02-java8-unix.tar.gz
              sudo tar -xvzf nexus-3.70.4-02-java8-unix.tar.gz
              sudo mv nexus-3.70.4-02 nexus
              sudo chown -R nexus:nexus /opt/nexus

              # Configure Nexus to run as nexus user
              echo 'run_as_user="nexus"' | sudo tee /opt/nexus/bin/nexus.rc

              # Create systemd service for Nexus
              cat &amp;lt;&amp;lt;EOF2 | sudo tee /etc/systemd/system/nexus.service
              [Unit]
              Description=Nexus Repository Manager
              After=network.target

              [Service]
              Type=forking
              LimitNOFILE=65536
              ExecStart=/opt/nexus/bin/nexus start
              ExecStop=/opt/nexus/bin/nexus stop
              User=nexus
              Restart=on-abort

              [Install]
              WantedBy=multi-user.target
              EOF2

              # Reload systemd and enable Nexus service
              sudo systemctl daemon-reexec
              sudo systemctl daemon-reload
              sudo systemctl enable nexus
              sudo systemctl start nexus

              # Print default admin password and Nexus URL
              echo -e "\n✅ Nexus is installed and running on port 8081."
              sudo cat /opt/sonatype-work/nexus3/admin.password
              echo -e "\n💡 Access Nexus at: http://$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4):8081"
&lt;/span&gt;&lt;span class="no"&gt;              EOF

&lt;/span&gt;  &lt;span class="c1"&gt;# Tags for the instance&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Nexus Server"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Security group to allow HTTP and HTTPS access&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_security_group"&lt;/span&gt; &lt;span class="s2"&gt;"nexus_sg"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nexus_sg"&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow HTTP, HTTPS, and SSH access"&lt;/span&gt;

  &lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;from_port&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8081&lt;/span&gt;
    &lt;span class="nx"&gt;to_port&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8081&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;cidr_blocks&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0/0"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;from_port&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
    &lt;span class="nx"&gt;to_port&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;cidr_blocks&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0/0"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;egress&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;from_port&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nx"&gt;to_port&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"-1"&lt;/span&gt;
    &lt;span class="nx"&gt;cidr_blocks&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"0.0.0.0/0"&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="nx"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"nexus_public_ip"&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="nx"&gt;aws_instance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nexus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;public_ip&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"The public IP address of the Nexus server"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h2&gt;
  
  
  Nexus Status
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgap9nodyhc1qd4ait37.png" alt="Image AWS Status" width="800" height="555"&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  4. Creating a Custom Gradle Plugin
&lt;/h2&gt;

&lt;p&gt;We created a Gradle plugin project to define reusable logic. Here’s how:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;build.gradle&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'java-gradle-plugin'&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'maven-publish'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'com.dependencie'&lt;/span&gt;
&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'1.0.0-SNAPSHOT'&lt;/span&gt;

&lt;span class="n"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;mavenCentral&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="nf"&gt;gradleApi&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="nf"&gt;localGroovy&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;gradlePlugin&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;backendPublisher&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'com.dependencie.nexusplugin'&lt;/span&gt;
            &lt;span class="n"&gt;implementationClass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'com.dependencie.nexusplugin.BackendPublisherPlugin'&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;publishing&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;maven&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nexusSnapshots"&lt;/span&gt;
            &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://&amp;lt;your-ec2-ip&amp;gt;:8081/repository/maven-snapshots/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;allowInsecureProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;
                &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"12345"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  Plugin Implementation (&lt;code&gt;BackendPublisherPlugin.java&lt;/code&gt;)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.dependencie.nexusplugin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.gradle.api.Plugin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.gradle.api.Project&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;


&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BackendPublisherPlugin&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Plugin&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Project&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Project&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPluginManager&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"java"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPluginManager&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"org.springframework.boot"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getPluginManager&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"io.spring.dependency-management"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setGroup&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.example"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setVersion&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"0.0.1-SNAPSHOT"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getExtensions&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getExtraProperties&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"springBootVersion"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"3.4.4"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRepositories&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;mavenCentral&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"implementation"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.springframework.boot:spring-boot-starter-data-jpa"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"implementation"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.springframework.boot:spring-boot-starter-web"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"implementation"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.springframework.boot"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"compileOnly"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.projectlombok:lombok"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"runtimeOnly"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"com.h2database:h2"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"annotationProcessor"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.projectlombok:lombok"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"testImplementation"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.springframework.boot:spring-boot-starter-test"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getDependencies&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"testRuntimeOnly"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"org.junit.platform:junit-platform-launcher"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Publishing the Plugin
&lt;/h3&gt;

&lt;p&gt;Run this in the plugin project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plugin will be published to your Nexus snapshot repository.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Using the Custom Plugin in a Backend Project
&lt;/h2&gt;

&lt;p&gt;Once published, we integrated the custom plugin into a Spring Boot project.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Backend Project Structure
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;settings.gradle&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;pluginManagement&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;maven&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://&amp;lt;your-ec2-ip&amp;gt;:8081/repository/maven-snapshots/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;allowInsecureProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;
                &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"12345"&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;gradlePluginPortal&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;mavenCentral&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;rootProject&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'employee-management'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'com.dependencie.nexusplugin'&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="s1"&gt;'1.0.0-SNAPSHOT'&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'java'&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'org.springframework.boot'&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="s1"&gt;'3.4.4'&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="s1"&gt;'io.spring.dependency-management'&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="s1"&gt;'1.1.7'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'com.example'&lt;/span&gt;
&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0.0.1-SNAPSHOT'&lt;/span&gt;

&lt;span class="n"&gt;java&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;toolchain&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;languageVersion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;JavaLanguageVersion&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;repositories&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;mavenCentral&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;maven&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http://&amp;lt;your-ec2-ip&amp;gt;:8081/repository/maven-snapshots/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;allowInsecureProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;
            &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"12345"&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="s1"&gt;'org.springframework.boot:spring-boot-starter-data-jpa'&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="s1"&gt;'org.springframework.boot:spring-boot-starter-web'&lt;/span&gt;
    &lt;span class="n"&gt;compileOnly&lt;/span&gt; &lt;span class="s1"&gt;'org.projectlombok:lombok'&lt;/span&gt;
    &lt;span class="n"&gt;annotationProcessor&lt;/span&gt; &lt;span class="s1"&gt;'org.projectlombok:lombok'&lt;/span&gt;
    &lt;span class="n"&gt;runtimeOnly&lt;/span&gt; &lt;span class="s1"&gt;'com.h2database:h2'&lt;/span&gt;
    &lt;span class="n"&gt;testImplementation&lt;/span&gt; &lt;span class="s1"&gt;'org.springframework.boot:spring-boot-starter-test'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;named&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'test'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;useJUnitPlatform&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verify Plugin Integration
&lt;/h3&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./gradlew helloPlugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ Custom Nexus Plugin Applied Successfully!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  6. Conclusion
&lt;/h2&gt;

&lt;p&gt;In this end-to-end setup, we:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deployed Sonatype Nexus on AWS EC2 using Terraform&lt;/li&gt;
&lt;li&gt;Created and published a custom Gradle plugin to Nexus&lt;/li&gt;
&lt;li&gt;Integrated that plugin into a Spring Boot backend project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup can be expanded further to publish internal libraries, enforce quality gates, or share reusable Gradle logic across teams.&lt;/p&gt;

</description>
      <category>nexus</category>
      <category>programming</category>
      <category>awschallenge</category>
      <category>vim</category>
    </item>
    <item>
      <title>Building a Chat Application with Ollama's DeepSeek Model</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Mon, 27 Jan 2025 12:59:08 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/building-a-chat-application-with-ollamas-deepseek-model-2m7i</link>
      <guid>https://dev.to/himanshusinghtomar/building-a-chat-application-with-ollamas-deepseek-model-2m7i</guid>
      <description>&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before diving in, ensure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A macOS system (Ollama is macOS-specific).&lt;/li&gt;
&lt;li&gt;Homebrew installed for package management.&lt;/li&gt;
&lt;li&gt;Basic familiarity with Angular or JavaScript for frontend development.&lt;/li&gt;
&lt;li&gt;You can download Ollama for all operating systems from &lt;a href="https://ollama.com/download" rel="noopener noreferrer"&gt;https://ollama.com/download&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Step 1: Installing Ollama
&lt;/h2&gt;

&lt;p&gt;Install Ollama using Homebrew by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;ollama
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, start the Ollama service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This launches the Ollama server locally, typically accessible at &lt;code&gt;http://localhost:11434&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Installing the Model
&lt;/h2&gt;

&lt;p&gt;To use the DeepSeek model, you first need to pull it into your local setup. Run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama pull deepseek-r1:8b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will download the model locally so it’s ready for use. If performance is a concern, consider pulling a smaller version of the model (e.g., &lt;code&gt;deepseek-r1:3b&lt;/code&gt;) if available.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: Testing the Model Locally
&lt;/h2&gt;

&lt;p&gt;To ensure everything is working, test the model by initiating a chat session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ollama chat deepseek-r1:8b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type your prompts and see the responses in your terminal. Exit the session when you’re ready to move forward.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Interacting with the Model via API
&lt;/h2&gt;

&lt;p&gt;Ollama provides an API endpoint that allows programmatic interaction with installed models. Here’s how you can do it in Angular.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Angular Project
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Angular CLI&lt;/strong&gt; (if not already installed):
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a new Angular project:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ng new chat-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add HttpClientModule:&lt;/strong&gt;
Update your &lt;code&gt;AppModule&lt;/code&gt; to include &lt;code&gt;HttpClientModule&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HttpClientModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
     &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
     &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;BrowserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpClientModule&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
     &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
     &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
   &lt;span class="p"&gt;})&lt;/span&gt;
   &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Angular Service for Chat
&lt;/h3&gt;

&lt;p&gt;Create a service to handle API communication:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HttpClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&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;Injectable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ChatService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:11434/api/chat&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;getChat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chatInput&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deepseek-r1:8b&lt;/span&gt;&lt;span class="dl"&gt;'&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;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;chatInput&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;stream&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="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&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;h3&gt;
  
  
  Angular Component for Chat
&lt;/h3&gt;

&lt;p&gt;Use the service in a component to interact with the API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ChatService&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./chat.service&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;input [(ngModel)]="chatInput" placeholder="Type your message" /&amp;gt;
      &amp;lt;button (click)="sendMessage()"&amp;gt;Send&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div *ngIf="chatResponse"&amp;gt;
      &amp;lt;p&amp;gt;{{ chatResponse }}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;chatInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;chatResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;chatService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ChatService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getChat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatInput&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="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatResponse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&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;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Adjust as per API response structure&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="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;h2&gt;
  
  
  Step 5: Optimizing Response Time
&lt;/h2&gt;

&lt;p&gt;If you notice that responses take too long, here are some optimizations:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use a Smaller Model
&lt;/h3&gt;

&lt;p&gt;Switch to a smaller version of the model if available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deepseek-r1:3b&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Smaller model for faster responses&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;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatInput&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;stream&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Add a System Message
&lt;/h3&gt;

&lt;p&gt;Guide the model to produce concise responses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deepseek-r1:8b&lt;/span&gt;&lt;span class="dl"&gt;'&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;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;system&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Respond concisely in plain text without Markdown or unnecessary tags.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatInput&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;stream&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Enable Streaming
&lt;/h3&gt;

&lt;p&gt;Streaming allows partial responses to be sent as they’re generated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;deepseek-r1:8b&lt;/span&gt;&lt;span class="dl"&gt;'&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;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chatInput&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;stream&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Handle the streamed response in chunks for faster perceived responses.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Optimize Server Performance
&lt;/h3&gt;

&lt;p&gt;Ensure the server has sufficient resources (CPU, memory, or GPU). If necessary, scale up your system resources to handle the model efficiently.&lt;/p&gt;




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

&lt;p&gt;In this guide, we explored how to set up and use Ollama's DeepSeek model with Angular. From installation to API integration and optimization, you now have a complete roadmap for building a functional chat application. By applying these techniques, you can ensure your application is both responsive and efficient.&lt;/p&gt;

&lt;p&gt;Feel free to experiment with system prompts and smaller models to tailor the chat experience to your needs. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Angular Life Cycle Hooks</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Sat, 25 Jan 2025 10:18:19 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/understanding-angular-life-cycle-hooks-oi4</link>
      <guid>https://dev.to/himanshusinghtomar/understanding-angular-life-cycle-hooks-oi4</guid>
      <description>&lt;p&gt;Angular is one of the most popular front-end frameworks for building dynamic web applications. A key aspect of Angular's power and flexibility lies in its component lifecycle hooks. These hooks provide developers with fine-grained control over how components and directives behave during their lifecycle. In this blog post, we will explore the most important lifecycle hooks that are commonly used in Angular applications, followed by a detailed explanation of all lifecycle hooks.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Angular Life Cycle Hooks?
&lt;/h2&gt;

&lt;p&gt;Lifecycle hooks are methods in a component or directive that Angular calls during specific stages of its creation, update, and destruction. By implementing these hooks, you can perform actions at crucial moments in a component's lifecycle, such as initializing data, responding to changes, or cleaning up resources.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Most Important Angular Lifecycle Hooks
&lt;/h2&gt;

&lt;p&gt;Here is a list of the most commonly used lifecycle hooks, along with their purpose and usage:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;ngOnChanges&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Responds to changes in the input properties bound to the component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngOnChanges(changes: SimpleChanges): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: Before &lt;code&gt;ngOnInit&lt;/code&gt;, whenever an input property changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hook is particularly useful when a component depends on dynamically changing input values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngOnChanges&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SimpleChanges&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Input property changed:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;changes&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;h3&gt;
  
  
  2. &lt;strong&gt;ngOnInit&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Used for component initialization, such as setting up data or making API calls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngOnInit(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: Once, after the first &lt;code&gt;ngOnChanges&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is one of the most frequently used hooks in Angular.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component initialized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;ngAfterViewInit&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Responds after Angular initializes the component's views and child views.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngAfterViewInit(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: Once, after the component's view is initialized.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hook is crucial when working with DOM manipulations or third-party libraries that depend on the DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngAfterViewInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;View initialized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;strong&gt;ngOnDestroy&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Performs cleanup before the component is destroyed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngOnDestroy(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: Just before the component is removed from the DOM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hook is essential for preventing memory leaks by unsubscribing from observables or removing event listeners.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngOnDestroy&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component destroyed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Detailed Explanation of All Angular Lifecycle Hooks
&lt;/h2&gt;

&lt;p&gt;In addition to the most commonly used hooks, Angular provides several other lifecycle hooks that can be leveraged in specific scenarios:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;ngDoCheck&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Detects and acts upon changes that Angular doesn't detect automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngDoCheck(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: During every change detection cycle.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngDoCheck&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Change detection triggered&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;ngAfterContentInit&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Responds after Angular projects external content into the component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngAfterContentInit(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: Once, after the first content projection.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngAfterContentInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content projected into the component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;ngAfterContentChecked&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Responds after Angular checks the projected content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngAfterContentChecked(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: After every change detection cycle.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngAfterContentChecked&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Projected content checked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;ngAfterViewChecked&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: Responds after Angular checks the component's views and child views.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: &lt;code&gt;ngAfterViewChecked(): void&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When Called&lt;/strong&gt;: After every change detection cycle.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngAfterViewChecked&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;View checked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Best Practices for Using Lifecycle Hooks
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Focus on Common Hooks&lt;/strong&gt;: While Angular provides many lifecycle hooks, focus on the most commonly used ones: &lt;code&gt;ngOnChanges&lt;/code&gt;, &lt;code&gt;ngOnInit&lt;/code&gt;, &lt;code&gt;ngAfterViewInit&lt;/code&gt;, and &lt;code&gt;ngOnDestroy&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid Memory Leaks&lt;/strong&gt;: Always clean up resources like subscriptions or event listeners in the &lt;code&gt;ngOnDestroy&lt;/code&gt; hook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Leverage ngOnInit&lt;/strong&gt;: Initialize data and make API calls in &lt;code&gt;ngOnInit&lt;/code&gt; rather than the constructor for better separation of concerns.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




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

&lt;p&gt;The lifecycle hooks &lt;code&gt;ngOnChanges&lt;/code&gt;, &lt;code&gt;ngOnInit&lt;/code&gt;, &lt;code&gt;ngAfterViewInit&lt;/code&gt;, and &lt;code&gt;ngOnDestroy&lt;/code&gt; are the most important and frequently used hooks in Angular development. However, understanding all lifecycle hooks such as &lt;code&gt;ngDoCheck&lt;/code&gt;, &lt;code&gt;ngAfterContentInit&lt;/code&gt;, &lt;code&gt;ngAfterContentChecked&lt;/code&gt;, and &lt;code&gt;ngAfterViewChecked&lt;/code&gt; ensures you have full control over your component's behavior. By mastering these hooks, you can deliver robust, high-quality applications with Angular.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>angular</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Work with HashMap in Java</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Fri, 24 Jan 2025 18:22:53 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/how-to-work-with-hashmap-in-java-4g8c</link>
      <guid>https://dev.to/himanshusinghtomar/how-to-work-with-hashmap-in-java-4g8c</guid>
      <description>&lt;p&gt;&lt;code&gt;HashMap&lt;/code&gt; is a powerful data structure in Java that allows you to store and manage key-value pairs efficiently. This guide will cover the basics of working with &lt;code&gt;HashMap&lt;/code&gt;, including commonly used methods and examples to help you understand its usage.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction to HashMap&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;HashMap&lt;/code&gt; stores data in the form of key-value pairs and provides constant-time complexity for basic operations like &lt;code&gt;put&lt;/code&gt;, &lt;code&gt;get&lt;/code&gt;, and &lt;code&gt;remove&lt;/code&gt; (on average). Here's why &lt;code&gt;HashMap&lt;/code&gt; is so useful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keys are unique&lt;/strong&gt;, but values can be duplicated.&lt;/li&gt;
&lt;li&gt;Keys and values can be of any object type.&lt;/li&gt;
&lt;li&gt;It is part of the &lt;code&gt;java.util&lt;/code&gt; package.&lt;/li&gt;
&lt;li&gt;It allows &lt;code&gt;null&lt;/code&gt; as a key or value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.HashMap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HashMapExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Adding key-value pairs&lt;/span&gt;
        &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apple"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Banana"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Cherry"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Accessing a value&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: Apple&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Creating a HashMap&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To create a &lt;code&gt;HashMap&lt;/code&gt;, use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;KeyType&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mapName&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;frequencyMap&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the key type is &lt;code&gt;String&lt;/code&gt; and the value type is &lt;code&gt;Integer&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Commonly Used Methods&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here are the key methods of &lt;code&gt;HashMap&lt;/code&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. &lt;code&gt;put(K key, V value)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Adds a key-value pair to the map. If the key already exists, it updates the value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;map&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Apple"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Banana"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Cherry"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Updates value for key 1&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {1=Cherry, 2=Banana}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;2. &lt;code&gt;get(Object key)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Retrieves the value associated with the specified key. Returns &lt;code&gt;null&lt;/code&gt; if the key is not found.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: Cherry&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;3. &lt;code&gt;getOrDefault(Object key, V defaultValue)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Retrieves the value for the specified key. Returns &lt;code&gt;defaultValue&lt;/code&gt; if the key is not found.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOrDefault&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Default"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: Default&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;4. &lt;code&gt;containsKey(Object key)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Checks if the map contains the specified key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;containsKey&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: true&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;containsKey&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;5. &lt;code&gt;containsValue(Object value)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Checks if the map contains the specified value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;containsValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cherry"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: true&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;containsValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Orange"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;6. &lt;code&gt;remove(Object key)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Removes the entry for the specified key and returns the value. Returns &lt;code&gt;null&lt;/code&gt; if the key is not found.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;remove&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Output: Cherry&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {2=Banana}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;7. &lt;code&gt;putIfAbsent(K key, V value)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Adds a key-value pair only if the key is not already present in the map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;putIfAbsent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Orange"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {2=Banana, 3=Orange}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;8. &lt;code&gt;replace(K key, V value)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Replaces the value associated with the key, only if the key exists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;replace&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Grapes"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {2=Banana, 3=Grapes}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;9. &lt;code&gt;keySet()&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Returns a &lt;code&gt;Set&lt;/code&gt; containing all the keys in the map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;keySet&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: [2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;10. &lt;code&gt;values()&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Returns a &lt;code&gt;Collection&lt;/code&gt; of all the values in the map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;values&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: [Banana, Grapes]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;11. &lt;code&gt;entrySet()&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Returns a &lt;code&gt;Set&lt;/code&gt; of all key-value pairs (&lt;code&gt;Map.Entry&lt;/code&gt;) in the map.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;entrySet&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getKey&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" -&amp;gt; "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// Output:&lt;/span&gt;
  &lt;span class="c1"&gt;// 2 -&amp;gt; Banana&lt;/span&gt;
  &lt;span class="c1"&gt;// 3 -&amp;gt; Grapes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;12. &lt;code&gt;compute(K key, BiFunction&amp;lt;? super K, ? super V, ? extends V&amp;gt; remappingFunction)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Updates the value for the given key using a computation function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Doubles the value&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {1=20}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;13. &lt;code&gt;merge(K key, V value, BiFunction&amp;lt;? super V, ? super V, ? extends V&amp;gt; remappingFunction)&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Combines a new value with the existing value for the given key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;merge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;Integer:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;sum&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Adds the values&lt;/span&gt;
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {1=15}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Full Example: Word Frequency Counter&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here is a complete example that demonstrates how to use &lt;code&gt;HashMap&lt;/code&gt; to count the frequency of words:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.HashMap&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WordFrequency&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"apple"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"banana"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"apple"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"orange"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"banana"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"apple"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;
        &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;frequencyMap&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;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;frequencyMap&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;frequencyMap&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getOrDefault&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frequencyMap&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: {orange=1, banana=2, apple=3}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






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

&lt;p&gt;The &lt;code&gt;HashMap&lt;/code&gt; class is a versatile and efficient way to manage key-value pairs in Java. By understanding its methods, you can solve a wide range of problems, from simple lookups to complex data manipulations. Start using &lt;code&gt;HashMap&lt;/code&gt; in your projects to leverage its power!&lt;/p&gt;

</description>
      <category>java</category>
      <category>hashmap</category>
      <category>springboot</category>
      <category>security</category>
    </item>
    <item>
      <title>Automating Google Meet Creation</title>
      <dc:creator>Himanshu Singh Tomar</dc:creator>
      <pubDate>Wed, 15 Jan 2025 10:28:01 +0000</pubDate>
      <link>https://dev.to/himanshusinghtomar/automating-google-meet-creation-14mo</link>
      <guid>https://dev.to/himanshusinghtomar/automating-google-meet-creation-14mo</guid>
      <description>&lt;h1&gt;
  
  
  Automating Google Meet Creation with Google Calendar API and Service Account
&lt;/h1&gt;

&lt;p&gt;In this blog post, we will walk through the process of automatically creating a Google Meet link by creating a Google Calendar event using the Google Calendar API. We'll use a service account to authenticate, making it possible to create events on behalf of a user in your Google Workspace domain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we get started, make sure you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Google Cloud Project&lt;/strong&gt; with the &lt;strong&gt;Google Calendar API&lt;/strong&gt; enabled.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Service Account&lt;/strong&gt; created and its JSON key file downloaded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain-Wide Delegation of Authority&lt;/strong&gt; enabled for the Service Account.&lt;/li&gt;
&lt;li&gt;Access to your &lt;strong&gt;Google Admin Console&lt;/strong&gt; to grant the necessary permissions.&lt;/li&gt;
&lt;li&gt;Basic knowledge of Node.js and API requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps to Create Google Meet Automatically
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Set Up Google Cloud Project
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to the &lt;a href="https://console.cloud.google.com/" rel="noopener noreferrer"&gt;Google Cloud Console&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a new project or select an existing one.&lt;/li&gt;
&lt;li&gt;Enable the &lt;strong&gt;Google Calendar API&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;In the sidebar, search for &lt;strong&gt;Calendar API&lt;/strong&gt; and enable it for your project.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Create a &lt;strong&gt;Service Account&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;IAM &amp;amp; Admin&lt;/strong&gt; section, create a new service account.&lt;/li&gt;
&lt;li&gt;Download the &lt;strong&gt;JSON key&lt;/strong&gt; for the service account.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Enable Domain-Wide Delegation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to the &lt;strong&gt;Google Admin Console&lt;/strong&gt; (&lt;a href="https://admin.google.com/" rel="noopener noreferrer"&gt;admin.google.com&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Security&lt;/strong&gt; → &lt;strong&gt;API Controls&lt;/strong&gt; → &lt;strong&gt;Manage Domain-Wide Delegation&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Add a new &lt;strong&gt;Client ID&lt;/strong&gt; for the service account:

&lt;ul&gt;
&lt;li&gt;Find the &lt;strong&gt;Client ID&lt;/strong&gt; in the &lt;strong&gt;Google Cloud Console&lt;/strong&gt; under your service account.&lt;/li&gt;
&lt;li&gt;Add the service account’s &lt;strong&gt;OAuth scopes&lt;/strong&gt;, which are required for accessing Google Calendar:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;https://www.googleapis.com/auth/calendar&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Grant the service account permission to impersonate users in your domain.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3: Install Required Packages
&lt;/h3&gt;

&lt;p&gt;You need a few Node.js packages to interact with the Google API and handle JWT signing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;google-auth-library jsonwebtoken node-fetch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Generate JWT Token for Authentication
&lt;/h3&gt;

&lt;p&gt;Next, we’ll write a Node.js script to generate a JWT (JSON Web Token) to authenticate the service account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&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;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Path to your service account JSON file&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SERVICE_ACCOUNT_KEY_FILE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/path/to/your/service-account-key.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Scopes required for the API&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SCOPES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.googleapis.com/auth/calendar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Full calendar access&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AUDIENCE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://oauth2.googleapis.com/token&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateJWT&lt;/span&gt;&lt;span class="p"&gt;()&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="c1"&gt;// Read and parse the service account credentials&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;serviceAccount&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;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SERVICE_ACCOUNT_KEY_FILE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;// JWT payload&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwtPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;iss&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;serviceAccount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client_email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;       &lt;span class="c1"&gt;// Issuer: service account email&lt;/span&gt;
            &lt;span class="na"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user@example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                &lt;span class="c1"&gt;// Subject: email of the user whose calendar to access&lt;/span&gt;
            &lt;span class="na"&gt;aud&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AUDIENCE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                          &lt;span class="c1"&gt;// Audience: Google token URL&lt;/span&gt;
            &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SCOPES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;                &lt;span class="c1"&gt;// Scopes: space-separated list of scopes&lt;/span&gt;
            &lt;span class="na"&gt;iat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;     &lt;span class="c1"&gt;// Issued at: current time in seconds&lt;/span&gt;
            &lt;span class="na"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="c1"&gt;// Expiration: 1 hour from now&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;

        &lt;span class="c1"&gt;// Sign the JWT using the service account's private key&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;signedJwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jwtPayload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;serviceAccount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;private_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;algorithm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RS256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Generated JWT:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signedJwt&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;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error generating JWT:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;generateJWT&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Exchange JWT for OAuth 2.0 Token
&lt;/h3&gt;

&lt;p&gt;Now, use the JWT to obtain an OAuth 2.0 token from Google’s OAuth 2.0 token endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node-fetch&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getAccessToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;signedJwt&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;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://oauth2.googleapis.com/token&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/x-www-form-urlencoded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;grant_type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;urn:ietf:params:oauth:grant-type:jwt-bearer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;assertion&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;signedJwt&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;access_token&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;h3&gt;
  
  
  Step 6: Create a Google Calendar Event with Google Meet Link
&lt;/h3&gt;

&lt;p&gt;Using the access token, we can now create a Google Calendar event with a Google Meet link.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCalendarEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accessToken&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;eventData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Meeting with Rajeen Test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Discuss project updates&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;dateTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2025-01-16T10:00:00+05:30&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Start time in IST&lt;/span&gt;
            &lt;span class="na"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Asia/Kolkata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;               &lt;span class="c1"&gt;// Explicitly specify IST time zone&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;end&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;dateTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2025-01-16T12:00:00+05:30&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// End time in IST&lt;/span&gt;
            &lt;span class="na"&gt;timeZone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Asia/Kolkata&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;               &lt;span class="c1"&gt;// Explicitly specify IST time zone&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;attendees&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;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;attendees1@gmail.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;attendees2@pieworks.in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="na"&gt;conferenceDataVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Add this to enable Meet links&lt;/span&gt;
        &lt;span class="na"&gt;conferenceData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;createRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;conferenceSolutionKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hangoutsMeet&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;requestId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unique-request-id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;


    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://www.googleapis.com/calendar/v3/calendars/primary/events?conferenceDataVersion=1&amp;amp;sendUpdates=all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//&amp;amp;sendUpdates=all (this is to send maill notification)&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;eventData&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;responseBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error creating event:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;responseBody&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Failed to create calendar event&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Event created successfully:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;responseBody&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Meet Link:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;responseBody&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hangoutLink&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Print the Google Meet link&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Run the Full Process
&lt;/h3&gt;

&lt;p&gt;Combine all the parts and run the script to create the Google Meet event automatically.&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;signedJwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;generateJWT&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;accessToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getAccessToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;signedJwt&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;createEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accessToken&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;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;With the above steps, you can create Google Calendar events with Google Meet links automatically, using a service account and Domain-Wide Delegation of Authority. This method is perfect for automating meetings in a Google Workspace domain.&lt;/p&gt;

&lt;p&gt;By enabling Domain-Wide Delegation and configuring the service account to impersonate users, you can access and manage Google Calendar events programmatically, which is extremely useful for enterprise environments.&lt;/p&gt;

&lt;p&gt;Happy coding! ✨&lt;/p&gt;

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