<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pankajbhargv on Medium]]></title>
        <description><![CDATA[Stories by Pankajbhargv on Medium]]></description>
        <link>https://medium.com/@pankajbhargv?source=rss-ce4fb6734d27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DJ155_a5vmR7OW42YR10Ag.jpeg</url>
            <title>Stories by Pankajbhargv on Medium</title>
            <link>https://medium.com/@pankajbhargv?source=rss-ce4fb6734d27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:53:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pankajbhargv/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TCP vs UDP vs QUIC: Understanding the Transport Layer Without the Confusion]]></title>
            <link>https://pankajbhargv.medium.com/tcp-vs-udp-vs-quic-understanding-the-transport-layer-without-the-confusion-f52088bd37b0?source=rss-ce4fb6734d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/f52088bd37b0</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[quic]]></category>
            <category><![CDATA[tcp-vs-udp]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[transport-protocol]]></category>
            <dc:creator><![CDATA[Pankajbhargv]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 18:54:53 GMT</pubDate>
            <atom:updated>2026-08-12T18:54:53.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*rwQOCy8d1w0KZ6lPth0I8A.png" /></figure><p>If you have ever worked with web applications, APIs, cloud systems, microservices, or distributed systems, you have probably heard these three names:</p><p><strong>TCP. UDP. QUIC.</strong></p><p>Most developers know that TCP is “reliable” and UDP is “faster.”</p><p>But that explanation is incomplete.</p><p>Why does HTTP/2 use TCP?</p><p>Why does HTTP/3 use QUIC?</p><p>Why does QUIC use UDP if UDP is unreliable?</p><p>And most importantly:</p><p><strong>When should you actually use TCP, UDP, or QUIC?</strong></p><p>Let’s understand all three from scratch using simple examples and then gradually move toward the technical details.</p><h3>1. First: Where does TCP, UDP and QUIC fit?</h3><p>Before understanding the protocols, we need to understand where they live.</p><p>A simplified networking stack looks like this:</p><pre>┌──────────────────────────────┐<br>│       Application Layer      │<br>│   HTTP / DNS / WebSocket     │<br>├──────────────────────────────┤<br>│       Transport Layer        │<br>│       TCP / UDP / QUIC       │<br>├──────────────────────────────┤<br>│         Network Layer        │<br>│             IP               │<br>├──────────────────────────────┤<br>│       Data Link / Physical   │<br>│       Wi-Fi / Ethernet       │<br>└──────────────────────────────┘</pre><p>The important thing to remember:</p><p><strong><em>IP helps deliver data between machines. Transport protocols help deliver data between applications/processes.</em></strong></p><p>For example:</p><pre>Laptop<br>192.168.1.10<br>      │<br>      │<br>      ↓<br>Server<br>142.x.x.x</pre><p>IP helps the packet reach the server.</p><p>But the server may be running hundreds of applications.</p><p>How does the operating system know which application should receive the data?</p><p>That’s where <strong>ports</strong> come in.</p><p>For example:</p><pre>142.x.x.x:443</pre><p>means:</p><pre>IP address → Which machine?<br>Port       → Which service/application?</pre><p>TCP, UDP and QUIC operate around this transport-level communication.</p><h3>2. The easiest analogy: sending packages</h3><p>Imagine you need to send 1,000 packages to a friend.</p><p>There are three different delivery systems.</p><h3>TCP</h3><p>The delivery company says:</p><p><strong><em>“I guarantee that every package arrives, and I’ll make sure everything is delivered in the correct order.”</em></strong></p><h3>UDP</h3><p>The delivery company says:</p><p><strong><em>“I’ll send the packages, but I won’t guarantee delivery or ordering.”</em></strong></p><h3>QUIC</h3><p>QUIC says:</p><p><strong><em>“I’ll use the simple UDP delivery mechanism, but I’ll build my own reliable delivery system on top of it — with multiple independent lanes and modern security.”</em></strong></p><p>That is the fundamental difference.</p><h3>3. TCP — Transmission Control Protocol</h3><p>TCP stands for:</p><p><strong>Transmission Control Protocol</strong></p><p>Its fundamental promise is:</p><blockquote><strong><em>Reliable, ordered, connection-oriented communication.</em></strong></blockquote><p>A simplified stack:</p><pre>Application<br>     ↓<br>    TCP<br>     ↓<br>     IP</pre><p>TCP gives the application a:</p><blockquote><strong><em>Reliable, ordered byte stream.</em></strong></blockquote><p>This sentence is worth remembering.</p><h3>4. What does “reliable” actually mean?</h3><p>Suppose you send:</p><pre>A B C D E</pre><p>But something goes wrong in the network:</p><pre>A B ❌ D E</pre><p>TCP can detect that some data is missing and arrange for the missing data to be retransmitted.</p><p>The application eventually receives:</p><pre>A B C D E</pre><p>It doesn’t have to implement packet-loss recovery itself.</p><p>That’s what TCP reliability means.</p><h3>5. What does “ordered” mean?</h3><p>Suppose packets arrive at the destination like this:</p><pre>Packet 1<br>Packet 3<br>Packet 2<br>Packet 5<br>Packet 4</pre><p>TCP doesn’t simply give them to the application in that order.</p><p>It reconstructs the byte stream and delivers the data in order:</p><pre>Packet 1<br>Packet 2<br>Packet 3<br>Packet 4<br>Packet 5</pre><p>This is extremely useful when every piece of data matters.</p><h3>6. TCP is connection-oriented</h3><p>Before sending application data, TCP establishes a connection.</p><p>This is done using the famous:</p><p><strong>Three-way handshake.</strong></p><pre>Client                         Server</pre><pre>   SYN ------------------------&gt;</pre><pre>       &lt;---------------- SYN + ACK</pre><pre>   ACK ------------------------&gt;</pre><pre>          Connection established</pre><h3>What is happening?</h3><p>The client says:</p><blockquote><em>“I want to establish a TCP connection.”</em></blockquote><p>That’s:</p><pre>SYN</pre><p>The server responds:</p><blockquote><em>“I received your request, and I also want to establish the connection.”</em></blockquote><p>That’s:</p><pre>SYN + ACK</pre><p>The client confirms:</p><blockquote><em>“Got it.”</em></blockquote><p>That’s:</p><pre>ACK</pre><p>Now the connection is established.</p><h3>7. Why does TCP need a handshake?</h3><p>Because both sides need to establish communication state.</p><p>TCP needs to track things such as:</p><ul><li>sequence numbers</li><li>acknowledgements</li><li>windows</li><li>connection state</li><li>retransmission information</li></ul><p>The handshake allows both sides to establish the initial state required for communication.</p><h3>8. TCP uses sequence numbers</h3><p>Imagine you’re sending:</p><pre>HELLO WORLD</pre><p>The data is represented as a stream of bytes.</p><p>TCP assigns sequence numbers to transmitted data.</p><p>Conceptually:</p><pre>H E L L O<br>1 2 3 4 5</pre><p>This helps TCP determine:</p><ul><li>what data has arrived</li><li>what data is missing</li><li>what needs retransmission</li><li>how to reconstruct the ordered stream</li></ul><h3>9. TCP acknowledgements</h3><p>TCP also uses acknowledgements.</p><p>Imagine:</p><pre>Sender<br>  |<br>  | Data<br>  ↓<br>Receiver<br>  |<br>  | ACK<br>  ↓<br>Sender</pre><p>The receiver tells the sender:</p><p><strong><em>“I received the data up to this point.”</em></strong></p><p>If the sender doesn’t receive the expected acknowledgement within an appropriate period, TCP can retransmit the missing data.</p><h3>10. TCP is a byte stream, not a message protocol</h3><p>This is a subtle but important concept.</p><p>Suppose an application does:</p><pre>send(&quot;HELLO&quot;)<br>send(&quot;WORLD&quot;)</pre><p>TCP doesn’t guarantee that the receiver will see:</p><pre>HELLO<br>WORLD</pre><p>as two separate messages.</p><p>The receiver might observe:</p><pre>HELLOWORLD</pre><p>or potentially receive the bytes in multiple reads.</p><p>TCP simply provides:</p><blockquote><strong><em>An ordered stream of bytes.</em></strong></blockquote><p>The application protocol must define message boundaries if it needs them.</p><p>This is an important distinction between TCP and UDP.</p><h3>11. TCP Flow Control</h3><p>Imagine a very fast sender communicating with a slow receiver.</p><pre>Fast sender<br>   ↓↓↓↓↓↓↓↓↓<br>Slow receiver</pre><p>If the sender continuously sends data at maximum speed, the receiver’s buffers could become overwhelmed.</p><p>TCP solves this using <strong>flow control</strong>.</p><p>The receiver effectively tells the sender:</p><blockquote><em>“This is how much data I can currently handle.”</em></blockquote><p>This is associated with TCP’s <strong>receive window</strong>.</p><p>So:</p><blockquote><strong><em>Flow control protects the receiver.</em></strong></blockquote><p>Remember that sentence.</p><h3>12. TCP Congestion Control</h3><p>Now imagine the receiver is fast.</p><p>But the network between them is overloaded.</p><pre>Sender<br>  ↓<br>Router<br>  ↓<br>🚦 Congested network<br>  ↓<br>Router<br>  ↓<br>Receiver</pre><p>Sending faster will make the network even more congested.</p><p>TCP therefore uses <strong>congestion control</strong> to adjust its sending behavior based on network conditions.</p><p>So:</p><blockquote><strong><em>Flow control protects the receiver.</em></strong></blockquote><blockquote><strong><em>Congestion control protects the network.</em></strong></blockquote><p>This distinction is frequently useful in interviews.</p><h3>13. TCP connection termination</h3><p>TCP connections are generally terminated using a sequence involving:</p><pre>FIN<br>ACK<br>FIN<br>ACK</pre><p>Why multiple messages?</p><p>Because TCP is full-duplex.</p><p>The two directions of communication can be closed independently.</p><h3>14. TCP TIME_WAIT</h3><p>You may encounter:</p><pre>TIME_WAIT</pre><p>when examining TCP connections.</p><p>TIME_WAIT exists to help ensure that delayed packets from an old connection don’t interfere with a later connection using the same connection identifiers.</p><p>You don’t need to memorize every TCP state initially.</p><p>But as an engineer, you should recognize states such as:</p><pre>LISTEN<br>SYN-SENT<br>SYN-RECEIVED<br>ESTABLISHED<br>FIN-WAIT<br>CLOSE-WAIT<br>TIME-WAIT</pre><h3>15. When should you use TCP?</h3><p>TCP is a natural choice when:</p><ul><li>data cannot be lost</li><li>order matters</li><li>retransmission is acceptable</li><li>reliability is more important than shaving every millisecond</li></ul><p>Examples:</p><pre>REST APIs<br>Banking systems<br>Payment systems<br>Database connections<br>File transfers<br>Email<br>Traditional web traffic</pre><p>For example, imagine transferring:</p><pre>₹10,000</pre><p>You absolutely don’t want:</p><pre>₹10,00 ❌</pre><p>or a transaction arriving in the wrong order.</p><p>Correctness matters.</p><p>TCP is therefore a natural fit for many such applications.</p><h3>16. UDP — User Datagram Protocol</h3><p>Now let’s look at the opposite philosophy.</p><p>UDP stands for:</p><p><strong>User Datagram Protocol</strong></p><p>UDP is much simpler than TCP.</p><p>A simplified stack:</p><pre>Application<br>     ↓<br>    UDP<br>     ↓<br>     IP</pre><p>UDP provides:</p><ul><li>source/destination ports</li><li>datagrams</li><li>checksum</li></ul><p>But UDP itself does <strong>not</strong> provide TCP’s built-in:</p><ul><li>connection establishment</li><li>reliable delivery</li><li>retransmission</li><li>ordered byte-stream delivery</li><li>TCP-style flow control</li><li>TCP-style congestion control</li></ul><p>The application may implement additional mechanisms if needed.</p><h3>17. UDP is connectionless</h3><p>With TCP:</p><pre>Handshake<br>   ↓<br>Connection<br>   ↓<br>Data</pre><p>With UDP:</p><pre>Send datagram<br>Send datagram<br>Send datagram</pre><p>There is no TCP-style three-way handshake before sending UDP datagrams.</p><p>That makes UDP lightweight.</p><h3>18. UDP uses datagrams</h3><p>This is an important difference.</p><p>TCP gives you:</p><blockquote><em>A continuous byte stream.</em></blockquote><p>UDP gives you:</p><blockquote><em>Individual datagrams.</em></blockquote><p>Imagine sending:</p><pre>HELLO<br>WORLD</pre><p>with UDP.</p><p>The receiver can distinguish those datagrams:</p><pre>Datagram 1 → HELLO<br>Datagram 2 → WORLD</pre><p>UDP preserves datagram boundaries.</p><h3>19. Why would anyone want unreliable communication?</h3><p>At first, UDP sounds terrible.</p><p>Why would you intentionally use something that can lose packets?</p><p>Because sometimes:</p><blockquote><strong><em>Late data is worse than lost data.</em></strong></blockquote><p>Consider a multiplayer game.</p><p>Suppose your character’s position is:</p><pre>Position 100<br>Position 101<br>Position 102<br>Position 103<br>Position 104</pre><p>Imagine the packet containing:</p><pre>Position 101</pre><p>gets lost.</p><p>Do you really want the system to stop and say:</p><p><strong><em>“Wait! We must retransmit position 101 before we process 102, 103, and 104.”</em></strong></p><p>Probably not.</p><p>The latest position is what matters.</p><p>You’d rather continue:</p><pre>100<br>❌ 101<br>102<br>103<br>104</pre><p>The game can continue using the latest state.</p><h3>20. UDP’s biggest advantage</h3><p>UDP has very little transport-layer machinery compared with TCP.</p><p>That means applications can potentially achieve:</p><ul><li>low overhead</li><li>low latency</li><li>application-specific behavior</li></ul><p>Typical use cases include:</p><pre>Online gaming<br>Real-time voice<br>Real-time video<br>DNS<br>Some telemetry</pre><h3>21. But don’t say “real-time = UDP”</h3><p>This is a common interview mistake.</p><p>Real-time does <strong>not automatically mean UDP</strong>.</p><p>Consider a chat application.</p><p>Messages are real-time:</p><pre>Alice → &quot;Hello&quot;</pre><p>But losing that message isn’t acceptable.</p><p>So you might use:</p><pre>TCP</pre><p>or a reliable application protocol over another transport.</p><p>The correct question is:</p><p><strong><em>Can the application tolerate loss or delayed retransmission?</em></strong></p><p>Not:</p><p><strong><em>“Is the application real-time?”</em></strong></p><h3>22. TCP vs UDP with a simple example</h3><p>Imagine you’re designing a football game.</p><h3>Player movement</h3><pre>Player position:<br>100<br>101<br>102<br>103</pre><p>If 101 is lost:</p><pre>100<br>❌<br>102<br>103</pre><p>The game can continue.</p><p>UDP can make sense.</p><h3>Payment for an in-game purchase</h3><pre>₹499</pre><p>You absolutely cannot lose that transaction.</p><p>You need reliable communication.</p><p>TCP or another reliable transport is appropriate.</p><p>The same application can therefore use different communication mechanisms for different types of traffic.</p><h3>23. Now we reach QUIC</h3><p>QUIC is where modern networking becomes interesting.</p><p>QUIC is commonly expanded as:</p><p><strong>Quick UDP Internet Connections</strong></p><p>It is a modern transport protocol designed to provide reliable, secure, multiplexed communication while running over UDP.</p><p>The important architecture is:</p><pre>HTTP/3<br>   ↓<br> QUIC<br>   ↓<br> UDP<br>   ↓<br> IP</pre><h3>24. Why was QUIC created?</h3><p>TCP is extremely successful.</p><p>But the Internet evolved.</p><p>Modern applications increasingly need:</p><ul><li>low connection latency</li><li>multiple independent streams</li><li>encrypted communication</li><li>mobile network changes</li><li>application-level control over transport behavior</li></ul><p>Changing TCP itself is difficult because TCP is deeply integrated into operating systems and network infrastructure.</p><p>QUIC takes another approach:</p><blockquote><em>Build a modern transport protocol on top of UDP.</em></blockquote><p>UDP gives QUIC a simple foundation.</p><p>QUIC adds the sophisticated features.</p><h3>25. The biggest misconception about QUIC</h3><p>You might think:</p><p><strong><em>“If QUIC runs on UDP, then QUIC must be unreliable.”</em></strong></p><p>No.</p><p>This is one of the most important things to understand.</p><p>UDP itself is unreliable.</p><p>But <strong>QUIC implements reliability on top of UDP</strong>.</p><p>Think of it like this:</p><pre>UDP<br> ↓<br>Basic delivery mechanism<br> ↓<br>QUIC adds:<br> ├── Reliability<br> ├── Retransmission<br> ├── Congestion control<br> ├── Flow control<br> ├── Streams<br> ├── Security<br> └── Connection migration</pre><p>So QUIC is not simply “UDP.”</p><p>It’s a sophisticated transport protocol that uses UDP underneath.</p><h3>26. QUIC’s biggest idea: multiple independent streams</h3><p>Imagine you’re loading a web page.</p><p>You need:</p><pre>HTML<br>CSS<br>JavaScript<br>Image 1<br>Image 2<br>Image 3</pre><p>HTTP/2 can multiplex these over one TCP connection.</p><p>Conceptually:</p><pre>One TCP connection<br>       │<br>       ├── Stream 1 → HTML<br>       ├── Stream 2 → CSS<br>       ├── Stream 3 → JavaScript<br>       └── Stream 4 → Images</pre><p>This is great.</p><p>But TCP still provides one ordered byte stream underneath.</p><h3>27. What happens when TCP loses a packet?</h3><p>Suppose:</p><pre>Stream 1 → packet lost ❌</pre><p>TCP doesn’t understand HTTP/2’s independent streams.</p><p>It sees:</p><p><strong><em>“There is missing data in my byte stream.”</em></strong></p><p>TCP’s ordered delivery can therefore hold back later bytes until the missing data is recovered.</p><p>This contributes to <strong>head-of-line blocking at the TCP connection level</strong>.</p><h3>28. QUIC handles streams differently</h3><p>QUIC understands streams.</p><p>Conceptually:</p><pre>QUIC Connection<br>       │<br>       ├── Stream 1 → HTML<br>       ├── Stream 2 → CSS<br>       ├── Stream 3 → JavaScript<br>       └── Stream 4 → Image</pre><p>Suppose Stream 1 has packet loss:</p><pre>Stream 1 → ❌<br>Stream 2 → continues<br>Stream 3 → continues<br>Stream 4 → continues</pre><p>The loss doesn’t necessarily block progress on unrelated streams.</p><p>This is one of the key reasons QUIC is useful for HTTP/3.</p><h3>29. QUIC and TLS</h3><p>Security is another major part of QUIC.</p><p>Traditional HTTPS commonly involves:</p><pre>HTTP<br> ↓<br>TLS<br> ↓<br>TCP<br> ↓<br>IP</pre><p>QUIC integrates TLS 1.3 into its protocol design.</p><p>With HTTP/3:</p><pre>HTTP/3<br> ↓<br>QUIC + TLS<br> ↓<br>UDP<br> ↓<br>IP</pre><p>This provides secure communication while allowing QUIC to design connection establishment and transport behavior together.</p><h3>30. Why is faster connection establishment important?</h3><p>Suppose you open a website.</p><p>With traditional TCP-based HTTPS, there are connection-establishment steps involving TCP and TLS before normal application data can flow.</p><p>Conceptually:</p><pre>TCP handshake<br>      ↓<br>TLS handshake<br>      ↓<br>HTTP request</pre><p>QUIC combines transport and cryptographic handshake design more tightly.</p><p>Conceptually:</p><pre>QUIC + TLS<br>      ↓<br>HTTP/3</pre><p>This can reduce the latency before useful application data can be exchanged, particularly for new connections.</p><h3>31. QUIC and mobile networks</h3><p>Imagine you’re using your phone.</p><p>At home:</p><pre>Wi-Fi</pre><p>Then you leave the house:</p><pre>4G/5G</pre><p>Your network path and IP address may change.</p><p>With traditional TCP, this can require the connection to be re-established.</p><p>QUIC uses a <strong>Connection ID</strong> that is not simply the client’s IP address and port.</p><p>This allows a QUIC connection to potentially survive a network change.</p><p>Conceptually:</p><pre>Same QUIC Connection ID<br>                       │<br>             ┌─────────┴─────────┐<br>             ↓                   ↓<br>           Wi-Fi                5G<br>          IP #1                 IP #2</pre><p>This feature is called <strong>connection migration</strong>.</p><p>It’s particularly useful for mobile clients.</p><h3>32. HTTP/1.1 vs HTTP/2 vs HTTP/3</h3><p>Now we can finally connect everything.</p><h3>HTTP/1.1</h3><pre>HTTP/1.1<br>   ↓<br> TCP<br>   ↓<br> IP</pre><h3>HTTP/2</h3><pre>HTTP/2<br>   ↓<br> TCP<br>   ↓<br> IP</pre><p>HTTP/2 introduced multiplexing, binary framing and header compression.</p><h3>HTTP/3</h3><pre>HTTP/3<br>   ↓<br> QUIC<br>   ↓<br> UDP<br>   ↓<br> IP</pre><p>HTTP/3 uses QUIC’s stream and transport capabilities.</p><h3>33. A simple evolution story</h3><p>You can remember the history like this:</p><h3>TCP</h3><blockquote><em>“Let’s make communication reliable.”</em></blockquote><pre>Reliable<br>Ordered<br>Connection-oriented</pre><h3>UDP</h3><blockquote><em>“Let’s keep transport extremely lightweight.”</em></blockquote><pre>Simple<br>Connectionless<br>Datagrams</pre><h3>QUIC</h3><blockquote><em>“Let’s build a modern transport protocol using UDP as the foundation.”</em></blockquote><pre>Reliable<br>Secure<br>Multiplexed<br>Low-latency connection establishment<br>Connection migration</pre><p>That is the story.</p><h3>34. A very important nuance about “TCP is reliable”</h3><p>When we say:</p><blockquote><em>“TCP is reliable.”</em></blockquote><p>we mean TCP provides reliable transport semantics.</p><p>It does <strong>not</strong> mean:</p><blockquote><em>“The application will always succeed.”</em></blockquote><p>For example:</p><pre>TCP connection successful<br>       ↓<br>HTTP request<br>       ↓<br>Server crashes<br>       ↓<br>Application fails</pre><p>TCP reliability doesn’t guarantee application-level success.</p><p>It guarantees reliable delivery of the TCP byte stream under the connection’s transport semantics.</p><p>This distinction becomes important in distributed systems.</p><h3>35. Another important nuance: TCP does not understand HTTP</h3><p>TCP doesn’t know:</p><pre>GET /users<br>POST /orders<br>200 OK<br>404 Not Found</pre><p>TCP only knows about:</p><pre>bytes<br>sequence numbers<br>acknowledgements<br>windows<br>connection state</pre><p>HTTP understands:</p><pre>GET<br>POST<br>headers<br>status codes<br>URLs<br>responses</pre><p>That’s why layered architecture is so important.</p><pre>HTTP<br> ↓<br>TCP<br> ↓<br>IP</pre><p>Each protocol solves a different problem.</p><h3>36. How does a real HTTP request travel?</h3><p>Suppose you open:</p><pre>https://example.com/users/123</pre><p>At the application level:</p><pre>GET /users/123</pre><p>Then the layers process it.</p><h3>Application</h3><pre>HTTP request</pre><h3>Transport</h3><p>For HTTP/2:</p><pre>TCP</pre><p>For HTTP/3:</p><pre>QUIC → UDP</pre><h3>Network</h3><pre>IP</pre><h3>Network infrastructure</h3><pre>Your device<br>   ↓<br>Wi-Fi router<br>   ↓<br>ISP<br>   ↓<br>Internet<br>   ↓<br>Cloud network<br>   ↓<br>Load balancer<br>   ↓<br>Application server</pre><p>At the destination, the process happens in reverse.</p><h3>37. So which one should you choose?</h3><p>This is the part that matters most in system design.</p><p>Don’t start by asking:</p><p><strong><em>“Should I use TCP or UDP?”</em></strong></p><p>Start by asking:</p><p><strong><em>“What does my application need?”</em></strong></p><h3>Choose TCP when:</h3><pre>Every piece of data matters<br>        +<br>Order matters<br>        +<br>Retransmission is acceptable</pre><p>Examples:</p><pre>Banking<br>Payments<br>REST APIs<br>Database connections<br>File transfer<br>Traditional HTTP traffic</pre><h3>Choose UDP when:</h3><pre>Low latency matters<br>        +<br>Some packet loss is acceptable<br>        +<br>Fresh data is more valuable than old data</pre><p>Examples:</p><pre>Gaming<br>Voice<br>Real-time video<br>DNS</pre><h3>Consider QUIC when:</h3><pre>You want modern reliable transport<br>        +<br>Multiplexed streams<br>        +<br>Fast connection establishment<br>        +<br>Connection migration<br>        +<br>Modern TLS integration</pre><p>And remember:</p><pre>HTTP/3<br>   ↓<br>QUIC<br>   ↓<br>UDP</pre><h3>38. A practical example: video calling</h3><p>Imagine you’re designing a video calling application.</p><p>You have several types of data:</p><pre>Video<br>Audio<br>Chat<br>Call setup<br>Authentication</pre><p>You don’t necessarily have to use the same transport approach for everything.</p><h3>Video</h3><p>A little packet loss may be acceptable.</p><p>Old video data is quickly becoming useless.</p><p>Latency matters.</p><pre>UDP-based real-time transport</pre><p>can make sense.</p><h3>Chat</h3><p>The message:</p><p><strong><em>“I’ll call you tomorrow.”</em></strong></p><p>should not disappear.</p><p>Reliable communication is important.</p><pre>Reliable transport/application protocol</pre><p>makes more sense.</p><p>This teaches an important system-design lesson:</p><blockquote><strong><em>Protocol selection can be different for different types of traffic within the same application.</em></strong></blockquote><h3>39. Another example: online shopping</h3><p>Suppose you’re building Amazon-like shopping.</p><h3>Product browsing</h3><pre>GET /products</pre><p>Reliable response required.</p><pre>HTTP<br> ↓<br>TCP</pre><p>or potentially HTTP/3:</p><pre>HTTP/3<br> ↓<br>QUIC<br> ↓<br>UDP</pre><h3>Payment</h3><p>Reliability and correctness are critical.</p><p>You need reliable application communication and, more importantly, correct transactional semantics.</p><h3>Product images/video</h3><p>Different delivery and caching strategies may apply.</p><p>The important point is:</p><blockquote><strong><em>Don’t select a protocol just because it is popular. Select it based on the requirements.</em></strong></blockquote><h3>40. The interview answer to “TCP vs UDP?”</h3><p>A weak answer:</p><blockquote><em>“TCP is reliable and UDP is fast.”</em></blockquote><p>A much stronger answer:</p><blockquote><em>“I’d choose based on the application’s tolerance for packet loss and latency. TCP provides a reliable, ordered byte stream and is appropriate when correctness and delivery are important. UDP provides lightweight datagrams and is useful when low latency and freshness are more important than guaranteed delivery. If I need modern reliable transport with multiplexed streams and features such as connection migration, I’d consider QUIC, which runs over UDP.”</em></blockquote><p>That demonstrates understanding rather than memorization.</p><h3>41. The three protocols in one picture</h3><p>If you remember only one diagram from this article, remember this:</p><pre>APPLICATION<br>                         │<br>                    ┌────┴────┐<br>                    │         │<br>                  HTTP      Other Apps<br>                    │<br>              ┌─────┴─────┐<br>              │           │<br>           HTTP/2       HTTP/3<br>              │           │<br>             TCP        QUIC<br>              │           │<br>              │          UDP<br>              │           │<br>              └─────┬─────┘<br>                    │<br>                   IP<br>                    │<br>                 Network</pre><p>And remember:</p><pre>TCP  → Reliable + ordered byte stream</pre><pre>UDP  → Lightweight + connectionless datagrams</pre><pre>QUIC → Modern reliable transport over UDP</pre><h3>42. Final mental model</h3><p>Think about the three protocols as three philosophies.</p><h3>TCP</h3><p><strong>“I care about getting everything there correctly.”</strong></p><pre>Reliability<br>Ordering<br>Connection</pre><h3>UDP</h3><p><strong>“I care about getting fresh data there quickly.”</strong></p><pre>Low overhead<br>Low latency<br>No built-in reliability</pre><h3>QUIC</h3><p><strong>“I want reliable modern transport, but I want more flexibility than traditional TCP provides.”</strong></p><pre>Reliability<br>Multiplexing<br>Security<br>Low-latency connection setup<br>Connection migration</pre><p>Once you understand these philosophies, the protocols stop being things you need to memorize.</p><p>You can reason about them.</p><p>And that’s the real skill: <strong>understanding why a protocol exists, what problem it solves, and what trade-offs it makes.</strong></p><p>Follow <a href="https://medium.com/u/ce4fb6734d27">Pankajbhargv</a> for such more articles</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f52088bd37b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attention Is All You Need — The Paper That Changed How We Build AI]]></title>
            <link>https://pankajbhargv.medium.com/attention-is-all-you-need-the-paper-that-changed-how-we-build-ai-b192305e9c72?source=rss-ce4fb6734d27------2</link>
            <guid isPermaLink="false">https://medium.com/p/b192305e9c72</guid>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[llm-architecture]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[ai-research]]></category>
            <dc:creator><![CDATA[Pankajbhargv]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 19:06:14 GMT</pubDate>
            <atom:updated>2026-08-11T19:06:14.522Z</atom:updated>
            <content:encoded><![CDATA[<h3>A beginner-friendly journey from words → attention → Transformers → modern LLMs</h3><p>Every time you ask ChatGPT a question, something interesting is happening behind the scenes.</p><p>The model isn’t simply looking at one word at a time.</p><p>It is constantly trying to figure out how different parts of your input relate to each other.</p><p>For example, if I write:</p><blockquote><strong><em>“The animal didn’t cross the road because it was too tired.”</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*-oPOrMY5nirUUdUS" /></figure><p>What does <strong>“it”</strong> refer to?</p><p>Most of us answer “the animal” without even thinking about it.</p><p>But for a machine, this is not obvious.</p><p>To understand the sentence, the model needs to connect <strong>“it”</strong> with <strong>“animal”</strong>, even though several other words sit between them.</p><p>This idea of figuring out <strong>which parts of the input matter to each other</strong> is what brings us to one of the most important ideas in modern AI:</p><h3>Attention</h3><p>And if you’ve spent any time learning about Generative AI, you’ve probably heard of another word:</p><p><strong>Transformer.</strong></p><p>Transformers are everywhere now.</p><p>GPT models, BERT, many modern LLMs, and a huge amount of today’s generative AI research are built around Transformer-based architectures.</p><p>But where did this idea come from?</p><p>One of the most important milestones was a 2017 research paper titled:</p><blockquote><strong><em>Attention Is All You Need</em></strong></blockquote><p>Eight researchers from Google and the University of Toronto proposed a new architecture called the <strong>Transformer</strong>.</p><p>The original problem they were trying to solve was machine translation.</p><p>The consequences of the idea turned out to be much bigger.</p><p>In this article, I want to go through the paper from the ground up.</p><p>Not by simply summarizing each section of the paper, but by building the ideas one at a time.</p><p>By the end, the original Transformer diagram should hopefully stop looking like a wall of boxes and arrows.</p><h3>Before we talk about Transformers, let’s talk about the problem</h3><p>Suppose we want to translate:</p><blockquote><strong><em>I love machine learning</em></strong></blockquote><p>into French:</p><blockquote><strong><em>J’aime l’apprentissage automatique</em></strong></blockquote><p>A neural network needs some way of processing the input sequence and producing the output sequence.</p><p>Before Transformers became popular, one common approach was to use <strong>Recurrent Neural Networks</strong>, or RNNs.</p><p>The basic idea is quite intuitive.</p><p>The model reads the sequence one step at a time:</p><pre>I<br> ↓<br>love<br> ↓<br>machine<br> ↓<br>learning</pre><p>At every step, the network maintains some internal state that carries information from previous words.</p><p>This makes sense.</p><p>But it also creates a problem.</p><p>To process:</p><blockquote><em>“machine”</em></blockquote><p>the model has to get through:</p><blockquote><em>“I” → “love”</em></blockquote><p>first.</p><p>And to process:</p><blockquote><em>“learning”</em></blockquote><p>it has to wait for everything before it.</p><p>The computation is inherently sequential.</p><p>And GPUs, which are extremely good at performing many mathematical operations in parallel, don’t particularly love this kind of dependency.</p><p>There was another problem too.</p><p>Consider:</p><blockquote><strong><em>“The animal didn’t cross the road because it was too tired.”</em></strong></blockquote><p>When we encounter <strong>“it”</strong>, we need to connect it with <strong>“animal.”</strong></p><p>As sentences become longer, maintaining useful information across many recurrent steps becomes increasingly difficult.</p><p>LSTMs and GRUs improved the situation significantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*igxYlKnC3NSacZrv" /></figure><p>But the underlying sequential structure was still there.</p><p>And this is where the Transformer paper asks a very interesting question:</p><blockquote><strong><em>Do we actually need recurrence at all?</em></strong></blockquote><h3>Attention existed before the Transformer</h3><p>This is an important detail.</p><p>The Transformer didn’t invent attention.</p><p>Attention mechanisms were already being used in neural machine translation systems.</p><p>The big idea in the 2017 paper was different.</p><p>The authors asked:</p><blockquote><em>What if we build the entire sequence-to-sequence architecture around attention instead of recurrence?</em></blockquote><p>And that’s exactly what they did.</p><p>They called the architecture:</p><h3>Transformer</h3><p>The paper’s central idea was surprisingly simple:</p><p><strong>Let the model directly look at relationships between tokens instead of forcing information to travel through a sequence one step at a time.</strong></p><p>That sounds simple.</p><p>The interesting part is how they actually made it work.</p><h3>So what exactly is “attention”?</h3><p>Let’s go back to our sentence:</p><blockquote><strong><em>The animal didn’t cross the road because it was too tired.</em></strong></blockquote><p>When the model processes <strong>“it”</strong>, not every word is equally useful.</p><p>The word:</p><blockquote><strong><em>animal</em></strong></blockquote><p>is probably much more relevant than:</p><blockquote><strong><em>road</em></strong></blockquote><p>or:</p><blockquote><strong><em>because</em></strong></blockquote><p>So we can imagine the model assigning different levels of importance to the other words.</p><p>Something like:</p><pre>The        0.05<br>animal     0.60<br>didn&#39;t     0.03<br>cross      0.02<br>the        0.03<br>road       0.05<br>because    0.04<br>it         —<br>was        0.05<br>tired      0.13</pre><p>These numbers are only illustrative.</p><p>The important idea is that the model is learning:</p><blockquote><strong><em>“When I’m trying to understand this token, which other tokens should I pay more attention to?”</em></strong></blockquote><p>That’s attention.</p><p>And this is probably the easiest way to develop an intuition for what the mechanism is doing.</p><h3>Query, Key and Value</h3><p>This is where I remember the paper becoming much less intuitive.</p><p>The paper describes attention using three things:</p><p><strong>Query (Q)</strong></p><p><strong>Key (K)</strong></p><p><strong>Value (V)</strong></p><p>At first, these names can feel unnecessarily abstract.</p><p>A simple analogy helps.</p><p>Imagine you’re searching in a library.</p><p>You walk in and say:</p><blockquote><em>“I want information about machine learning.”</em></blockquote><p>That’s your <strong>Query</strong>.</p><p>The books have descriptions or labels that tell you what they are about.</p><p>Those are the <strong>Keys</strong>.</p><p>Once you find the relevant books, you actually take the information inside them.</p><p>Those are the <strong>Values</strong>.</p><p>So, roughly:</p><pre>Query<br>  ↓<br>Compare against Keys<br>  ↓<br>Find what is relevant<br>  ↓<br>Retrieve corresponding Values</pre><p>That’s the intuition.</p><p>But the Transformer doesn’t literally have a library inside it.</p><p>Everything is represented as vectors and matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*-4FR-rrnjKr2-N27" /></figure><p>And that brings us to the famous equation.</p><h3>The equation that scares everyone</h3><p>The paper defines scaled dot-product attention as:</p><blockquote><strong><em>Attention(Q, K, V) = softmax(QKᵀ / √dₖ)V</em></strong></blockquote><p>If you have never studied this before, this equation looks much more complicated than it actually is.</p><p>The trick is to stop looking at it as one giant equation.</p><p>Break it into operations.</p><h3>1. Compare the Query with the Keys</h3><p>We calculate:</p><blockquote><strong><em>QKᵀ</em></strong></blockquote><p>This produces scores indicating how strongly different tokens relate to each other.</p><p>In simple terms:</p><blockquote><em>“How relevant is this word to that word?”</em></blockquote><h3>2. Scale the scores</h3><p>We divide by:</p><blockquote><strong><em>√dₖ</em></strong></blockquote><p>where dₖ is the dimensionality of the key vectors.</p><p>Why?</p><p>Because dot products can become large when the dimensionality of the vectors increases.</p><p>Very large values can make the softmax function behave poorly.</p><p>Scaling keeps the values in a more manageable range.</p><h3>3. Apply Softmax</h3><p>Softmax converts the scores into normalized attention weights.</p><p>For example:</p><pre>animal     0.62<br>road       0.08<br>because    0.10<br>tired      0.15<br>other      0.05</pre><p>Now we have something that tells us how much attention to give different pieces of information.</p><h3>4. Use those weights with the Values</h3><p>Finally, those attention weights are used to create a weighted combination of the Value vectors.</p><p>So the output isn’t simply:</p><blockquote><em>“The word animal is important.”</em></blockquote><p>The model actually incorporates information from the relevant tokens into the representation it is building.</p><p>That’s the core operation behind attention.</p><p>Once I stopped thinking of the equation as “one scary formula” and instead thought of it as:</p><blockquote><strong><em>compare → scale → normalize → combine information</em></strong></blockquote><p>it became much easier to understand.</p><h3>Self-Attention</h3><p>Now we can make one small but important change to our terminology.</p><p>What if the Query, Keys and Values all come from the <strong>same sequence</strong>?</p><p>That’s:</p><h3>Self-Attention</h3><p>Take:</p><blockquote><strong><em>The cat sat on the mat.</em></strong></blockquote><p>Each token can look at the other tokens in the same sentence.</p><p>Conceptually:</p><pre>The ──────────────┐<br>cat ──────────────┤<br>sat ──────────────┤<br>on ───────────────┼──→ Self-Attention<br>the ──────────────┤<br>mat ──────────────┘</pre><p>The model can learn relationships between tokens directly.</p><p>For example, when processing <strong>“cat”</strong>, it may pay attention to <strong>“sat.”</strong></p><p>When processing <strong>“mat”</strong>, it may pay attention to <strong>“on.”</strong></p><p>The exact relationships aren’t manually programmed.</p><p>The network learns them during training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*415Q1nGjf-kbiK-S" /></figure><h3>But why stop at one attention mechanism?</h3><p>This is another clever part of the architecture.</p><p>A sentence contains many different types of relationships.</p><p>For example, one relationship might be grammatical.</p><p>Another might be semantic.</p><p>Another might involve a long-distance dependency.</p><p>So why ask one attention mechanism to learn everything?</p><p>Instead, the Transformer uses several attention mechanisms in parallel.</p><p>This is called:</p><h3>Multi-Head Attention</h3><p>Imagine eight people reading the same sentence.</p><p>One person might focus on grammatical relationships.</p><p>Another might focus on which words describe which objects.</p><p>Another might focus on long-distance relationships.</p><p>Another might learn something completely different.</p><p>These are analogous to the different <strong>attention heads</strong>.</p><p>The outputs from the heads are then combined.</p><pre>Input<br>                      │<br>        ┌─────────────┼─────────────┐<br>        ↓             ↓             ↓<br>      Head 1        Head 2        Head 3 ... Head 8<br>        │             │             │<br>        └─────────────┼─────────────┘<br>                      ↓<br>                 Concatenate<br>                      ↓<br>                Linear Layer<br>                      ↓<br>                    Output</pre><p>The base Transformer described in the paper uses <strong>8 attention heads</strong>.</p><p>The important thing isn’t that there are exactly eight heads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*YoA_ac0SQf3CeFSI" /></figure><p>The important idea is:</p><blockquote><strong><em>Different attention heads can learn different relationships.</em></strong></blockquote><h3>There’s another problem: attention doesn’t know order</h3><p>Let’s take two sentences:</p><blockquote><strong><em>Dog bites man.</em></strong></blockquote><p>and:</p><blockquote><strong><em>Man bites dog.</em></strong></blockquote><p>Same three important words.</p><p>Completely different meaning.</p><p>So if attention looks at all the tokens, how does it know which one came first?</p><p>This is where another component becomes necessary.</p><h3>Positional Encoding</h3><p>The Transformer adds information about the position of each token.</p><p>For example:</p><pre>The       → position 1<br>cat       → position 2<br>sat       → position 3<br>on        → position 4<br>the       → position 5<br>mat       → position 6</pre><p>The original Transformer uses sinusoidal positional encodings.</p><p>Conceptually:</p><pre>Token Embedding<br>      +<br>Positional Encoding<br>      ↓<br>Input Representation</pre><p>The token embedding tells the model something about <strong>what the token is</strong>.</p><p>The positional encoding provides information about <strong>where it occurs</strong>.</p><p>The original paper used sinusoidal functions to construct these positional representations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*hHdg4JKt4YkWLYa3" /></figure><p>There are many other approaches to positional information in modern Transformer architectures, but for understanding the original paper, the key idea is simply:</p><blockquote><strong><em>Attention needs some way of knowing about token position.</em></strong></blockquote><h3>So far, we have only talked about vectors</h3><p>One thing that’s easy to forget when reading the paper is that computers don’t see:</p><blockquote><em>“The cat sat on the mat.”</em></blockquote><p>as English words.</p><p>The text first needs to be converted into tokens.</p><p>Those tokens are mapped to numerical representations.</p><p>For example, conceptually:</p><pre>&quot;cat&quot;<br>   ↓<br>[0.21, -0.44, 0.17, 0.82, ...]</pre><p>This is an <strong>embedding</strong>.</p><p>In the original base Transformer, the model dimension d_model is <strong>512</strong>.</p><p>So a token representation can be thought of as a vector with 512 dimensions.</p><p>We don’t need to imagine what each individual dimension means.</p><p>The important point is:</p><blockquote><strong><em>Language is converted into numbers, and the Transformer performs mathematical operations on those numbers.</em></strong></blockquote><h3>Now let’s build the Encoder</h3><p>At this point we’ve accumulated quite a few pieces:</p><ul><li>Token embeddings</li><li>Positional encoding</li><li>Self-attention</li><li>Multi-head attention</li><li>Feed-forward networks</li></ul><p>Now we can start assembling the actual Transformer.</p><p>The original architecture has two major parts:</p><p><strong>Encoder</strong></p><p>and</p><p><strong>Decoder</strong></p><p>Let’s start with the encoder.</p><p>The encoder receives the input sequence and builds contextual representations of it.</p><p>The original paper stacks <strong>6 encoder layers</strong>.</p><p>Each encoder layer contains two major sublayers:</p><ol><li>Multi-Head Self-Attention</li><li>Position-wise Feed-Forward Network</li></ol><p>with residual connections and layer normalization around them.</p><p>Conceptually:</p><pre>Input<br>  │<br>  ▼<br>Multi-Head Self-Attention<br>  │<br>  ▼<br>Add + LayerNorm<br>  │<br>  ▼<br>Feed-Forward Network<br>  │<br>  ▼<br>Add + LayerNorm<br>  │<br>  ▼<br>Output</pre><p>And this block is repeated six times in the base Transformer.</p><h3>What is the Feed-Forward Network doing?</h3><p>This part is actually less mysterious than it sounds.</p><p>After attention allows the tokens to exchange information, each token representation passes through a small neural network.</p><p>In the original Transformer, this is essentially:</p><pre>Linear<br>  ↓<br>ReLU<br>  ↓<br>Linear</pre><p>The base model expands the representation from:</p><blockquote><strong><em>512 → 2048</em></strong></blockquote><p>and then brings it back:</p><blockquote><strong><em>2048 → 512</em></strong></blockquote><p>So:</p><pre>512<br> ↓<br>2048<br> ↓<br>ReLU<br> ↓<br>512</pre><p>You can think of attention as helping tokens <strong>exchange information</strong>, while the feed-forward network performs additional transformation on each token representation.</p><p>That distinction is useful.</p><h3>And what is “Add &amp; Norm”?</h3><p>This is another part of the original diagram that looks more complicated than it is.</p><p>You will see something like:</p><pre>x ───────────────────┐<br>                     ↓<br>x → Layer → Add → LayerNorm</pre><p>The x being added back is the <strong>residual connection</strong>.</p><p>Instead of forcing the network to completely transform the input, the layer can learn a modification to the existing representation.</p><p>Residual connections became extremely important for training deep neural networks.</p><p>Then comes:</p><p><strong>Layer Normalization</strong></p><p>which helps stabilize the representations flowing through the network.</p><p>So when you see:</p><blockquote><strong><em>Add &amp; Norm</em></strong></blockquote><p>think:</p><blockquote><strong><em>Residual connection + Layer Normalization</em></strong></blockquote><h3>Now we need the Decoder</h3><p>The encoder has built representations of the input.</p><p>But our translation system still needs to generate the translated sentence.</p><p>That’s where the decoder comes in.</p><p>For example:</p><pre>Input:<br>I love machine learning</pre><pre>        ↓</pre><pre>Encoder</pre><pre>        ↓</pre><pre>Decoder</pre><pre>        ↓</pre><pre>J&#39;aime l&#39;apprentissage automatique</pre><p>The original Transformer also uses <strong>6 decoder layers</strong>.</p><p>Each decoder layer has three major components:</p><ol><li>Masked Multi-Head Self-Attention</li><li>Encoder-Decoder Attention</li><li>Feed-Forward Network</li></ol><p>And there is one important detail here that we shouldn’t skip.</p><h3>Why does the Decoder need masking?</h3><p>Suppose the decoder is generating:</p><blockquote><strong><em>“J’aime l’apprentissage automatique”</em></strong></blockquote><p>When the model is trying to predict the next token, it shouldn’t be allowed to look at the future answer.</p><p>Otherwise, it would be cheating.</p><p>Imagine predicting:</p><blockquote><strong><em>“machine”</em></strong></blockquote><p>while already seeing:</p><blockquote><strong><em>“learning”</em></strong></blockquote><p>The model would have access to information it isn’t supposed to have.</p><p>So the decoder uses <strong>masked self-attention</strong>.</p><p>Conceptually:</p><pre>I   love   machine   learning</pre><pre>I            ✓    ✗       ✗          ✗</pre><pre>love         ✓    ✓       ✗          ✗</pre><pre>machine      ✓    ✓       ✓          ✗</pre><pre>learning     ✓    ✓       ✓          ✓</pre><p>The current token can attend to previous tokens, but not future ones.</p><p>This is what allows autoregressive generation.</p><h3>Encoder-Decoder Attention</h3><p>The decoder actually needs two different kinds of information.</p><p>First:</p><blockquote><strong><em>What have I generated so far?</em></strong></blockquote><p>That’s handled by masked self-attention.</p><p>Second:</p><blockquote><strong><em>Which parts of the input should I look at?</em></strong></blockquote><p>That’s handled by the attention mechanism between the decoder and encoder.</p><p>This is often called:</p><p><strong>Cross-Attention</strong></p><p>For example, while generating part of the French translation, the decoder can attend to relevant representations produced by the encoder from the English sentence.</p><p>So there are really two different ideas happening inside the decoder:</p><pre>What have I generated?<br>        ↓<br>Masked Self-Attention</pre><pre>What should I look at in the input?<br>        ↓<br>Cross-Attention</pre><p>That distinction is worth remembering.</p><h3>Now we can finally look at the complete Transformer</h3><p>This is probably the point where I’d recommend going back to the original Transformer diagram.</p><p>At the beginning of this article, it probably looked like a collection of random boxes.</p><p>Now we have enough context to understand almost every major component.</p><p>The original architecture looks roughly like this:</p><pre>INPUT<br>                      │<br>                      ▼<br>              Token Embedding<br>                      +<br>             Positional Encoding<br>                      │<br>                      ▼<br>              ┌───────────────┐<br>              │   ENCODER     │<br>              │     × 6       │<br>              │               │<br>              │ Self-Attention│<br>              │       ↓       │<br>              │ Add + Norm    │<br>              │       ↓       │<br>              │ Feed Forward  │<br>              │       ↓       │<br>              │ Add + Norm    │<br>              └───────┬───────┘<br>                      │<br>                      │<br>                      ▼<br>              Encoder Output<br>                      │<br>                      │<br>                      ▼<br>              ┌───────────────┐<br>              │   DECODER     │<br>              │     × 6       │<br>              │               │<br>              │ Masked        │<br>              │ Self-Attention│<br>              │       ↓       │<br>              │ Add + Norm    │<br>              │       ↓       │<br>              │ Cross-Attn    │◄──── Encoder Output<br>              │       ↓       │<br>              │ Add + Norm    │<br>              │       ↓       │<br>              │ Feed Forward  │<br>              │       ↓       │<br>              │ Add + Norm    │<br>              └───────┬───────┘<br>                      │<br>                      ▼<br>                  Linear<br>                      │<br>                      ▼<br>                   Softmax<br>                      │<br>                      ▼<br>                Next Token</pre><p>And suddenly the diagram is much less intimidating.</p><p>That, for me, is the real value of learning the paper this way.</p><p>You don’t need to memorize the diagram.</p><p>You need to understand <strong>why each component exists</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*RTiZRMifiodcQdBE" /></figure><h3>So why was this such a big deal?</h3><p>The answer is not simply:</p><blockquote><em>“Attention is better than RNNs.”</em></blockquote><p>The bigger advantage was that Transformers were much more amenable to <strong>parallel computation during training</strong>.</p><p>An RNN has a dependency like:</p><pre>Token 1<br>   ↓<br>Token 2<br>   ↓<br>Token 3<br>   ↓<br>Token 4</pre><p>The Transformer can perform attention across the sequence using matrix operations that are much more suitable for GPUs and other accelerators.</p><p>That means much more computation can happen in parallel during training.</p><p>This was one of the major arguments in the original paper.</p><p>And the researchers backed it up with experiments.</p><h3>What did the original paper actually achieve?</h3><p>The paper evaluated the Transformer on machine translation benchmarks.</p><p>On the WMT 2014 English-to-German translation task, the Transformer achieved a <strong>28.4 BLEU score</strong>.</p><p>On English-to-French, the paper reported <strong>41.8 BLEU</strong> for its single model.</p><p>More interestingly, the authors reported training the model in a matter of days using eight GPUs.</p><p>For a paper introducing a completely different architecture, these results were significant.</p><p>The point wasn’t simply:</p><blockquote><em>“We got a better translation score.”</em></blockquote><p>The more interesting claim was:</p><blockquote><strong><em>A model without recurrence could achieve excellent sequence-to-sequence performance while being significantly more parallelizable.</em></strong></blockquote><p>That combination was powerful.</p><h3>But wait… where does GPT fit into all of this?</h3><p>This is where things get really interesting.</p><p>If you look at the original Transformer, you see:</p><pre>Encoder + Decoder</pre><p>But modern language models such as GPT don’t use exactly this architecture.</p><p>The Transformer became more like a foundation that researchers could modify for different problems.</p><p>A simplified view looks like this:</p><pre>Transformer<br>                     │<br>          ┌──────────┴──────────┐<br>          ↓                     ↓<br>       Encoder               Decoder<br>          │                     │<br>          ↓                     ↓<br>        BERT                   GPT</pre><p>BERT-style models are primarily built around the encoder side.</p><p>GPT-style models are built around the decoder/causal language-modeling side.</p><p>The training objective is also different from the original translation task.</p><p>This distinction is important.</p><p>When people say:</p><blockquote><em>“GPT is a Transformer”</em></blockquote><p>they are right.</p><p>But GPT isn’t simply the exact 2017 Transformer copied unchanged.</p><p>It’s a descendant of the architecture.</p><h3>The connection to modern LLMs</h3><p>Now let’s simplify what happens in an autoregressive language model.</p><p>Suppose the input is:</p><blockquote><strong><em>The capital of France is</em></strong></blockquote><p>The model processes the tokens and eventually produces a probability distribution over its vocabulary.</p><p>Conceptually:</p><pre>Paris       0.92<br>London      0.02<br>Berlin      0.01<br>Madrid      0.01<br>Tokyo       0.00<br>...</pre><p>The model selects a token.</p><blockquote><strong><em>Paris</em></strong></blockquote><p>Now the sequence becomes:</p><blockquote><strong><em>The capital of France is Paris</em></strong></blockquote><p>The model can then predict what comes next.</p><p>And this process repeats.</p><pre>Input<br>  ↓<br>Transformer<br>  ↓<br>Probability distribution<br>  ↓<br>Next token<br>  ↓<br>Add token to sequence<br>  ↓<br>Transformer again<br>  ↓<br>Next token<br>  ↓<br>...</pre><p>At a high level, this is the basic idea behind autoregressive text generation.</p><p>Of course, modern LLMs involve many additional techniques, optimizations, training strategies, and architectural changes.</p><p>But the Transformer is the foundation of the story.</p><h3>From one 2017 paper to modern AI</h3><p>This is the part I find most interesting when looking back at the paper.</p><p>The researchers were solving a machine translation problem.</p><p>They were not writing a paper called:</p><blockquote><em>“How to Build ChatGPT.”</em></blockquote><p>Yet their architecture became the foundation for a huge part of the modern AI ecosystem.</p><p>A simplified evolution looks like this:</p><pre>RNN / LSTM<br>    │<br>    ▼<br>Attention-based Models<br>    │<br>    ▼<br>2017 Transformer<br>    │<br>    ├──────────────┐<br>    ▼              ▼<br>  BERT            GPT<br>                    │<br>                    ▼<br>             Larger Transformers<br>                    │<br>                    ▼<br>               Modern LLMs<br>                    │<br>        ┌───────────┼───────────┐<br>        ↓           ↓           ↓<br>     Chatbots     Coding     Agents<br>        ↓<br>   Generative AI</pre><p>The real historical path is much more complicated than this diagram.</p><p>But the important connection is there.</p><p>A research idea developed for sequence-to-sequence translation became a foundation for today’s large-scale language models.</p><h3>What I think is actually worth remembering</h3><p>If you’re learning LLMs, preparing for an AI interview, or simply trying to understand what’s happening inside modern AI systems, I wouldn’t try to memorize the entire paper.</p><p>I’d make sure these concepts are clear:</p><h3>1. Self-Attention</h3><p>Tokens can dynamically determine which other tokens are relevant.</p><h3>2. Query, Key and Value</h3><p>The three vector representations used to calculate attention.</p><h3>3. Scaled Dot-Product Attention</h3><pre>softmax(QKᵀ / √dₖ)V</pre><p>Think:</p><blockquote><strong><em>Compare → Scale → Normalize → Combine</em></strong></blockquote><h3>4. Multi-Head Attention</h3><p>Multiple attention mechanisms can learn different relationships.</p><h3>5. Positional Encoding</h3><p>Attention needs information about token position.</p><h3>6. Feed-Forward Network</h3><p>Further transforms each token representation after attention.</p><h3>7. Residual Connections</h3><p>Help information and gradients flow through deep networks.</p><h3>8. Layer Normalization</h3><p>Helps stabilize the network.</p><h3>9. Masked Self-Attention</h3><p>Prevents the decoder from looking at future tokens.</p><h3>10. Cross-Attention</h3><p>Allows the decoder to use information from the encoder.</p><p>Once these pieces make sense, the Transformer architecture isn’t nearly as mysterious.</p><h3>One last thing</h3><p>When I first started reading about Transformers, I found myself trying to memorize diagrams.</p><p>That wasn’t particularly useful.</p><p>The more useful question turned out to be:</p><blockquote><strong><em>Why does this component exist?</em></strong></blockquote><p>Why attention?</p><p>Because tokens need to exchange information.</p><p>Why Q, K and V?</p><p>Because the model needs a mechanism to compare relevance and retrieve information.</p><p>Why multiple heads?</p><p>Because there are different relationships worth learning.</p><p>Why positional encoding?</p><p>Because attention alone doesn’t give us sequence order.</p><p>Why masking?</p><p>Because the decoder shouldn’t see the future.</p><p>Why residual connections?</p><p>Because deep networks are easier to train when information can flow through shortcut paths.</p><p>Once you understand those <strong>“whys,”</strong> the architecture starts making much more sense.</p><p>And that’s probably the biggest lesson I took away from reading <em>Attention Is All You Need</em>.</p><p>The paper wasn’t just introducing another neural network architecture.</p><p>It was questioning an assumption that had been central to sequence modeling:</p><blockquote><strong><em>Does a model really need to process a sequence one step at a time?</em></strong></blockquote><p>The answer turned out to be:</p><p><strong>No.</strong></p><p>And that seemingly simple answer changed the direction of AI research.</p><p>A paper written in 2017 to improve machine translation ended up laying one of the most important architectural foundations for the LLM era.</p><p>That’s quite a journey for a paper with such a simple title:</p><h3>Attention Is All You Need.</h3><p>Follow <a href="https://medium.com/u/ce4fb6734d27">Pankajbhargava</a> for more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b192305e9c72" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>