Skip to content
intermediatePhase ·

HTTP/2

Learn HTTP/2 multiplexing, header compression, and server push.

30m
0 problems
Topic Progress0%

HTTP/2 Features

HTTP/2 (RFC 7540, 2015) fixes the performance limitations of HTTP/1.1 with multiplexing, header compression, and server push.

HTTP/1.1 vs HTTP/2

HTTP/1.1 (Sequential):
Connection 1: [Request 1][Response 1][Request 2][Response 2]
Connection 2: [Request 3][Response 3][Request 4][Response 4]

HTTP/2 (Multiplexed):
Connection 1: [Req1][Req2][Req3][Req4]
              [Res1][Res2][Res3][Res4]  (interleaved)

Key HTTP/2 Features

Feature Description Benefit
Multiplexing Multiple requests over one connection Eliminates HOL blocking
Header Compression HPACK compression for headers Reduces overhead
Server Push Server proactively sends resources Faster page loads
Stream Priority Prioritize important requests Better UX

Multiplexing

HTTP/1.1:
  Connection 1: [===Request 1===]
  Connection 2: [===Request 2===]
  Connection 3: [===Request 3===]
  (6 connections max per domain)

HTTP/2:
  Single Connection:
  [Req1][Req2][Req3][Req4][Req5]
  [Res1][Res3][Res2][Res4][Res5]
  (all interleaved on one connection)

Header Compression (HPACK)

HTTP/1.1 Headers (uncompressed):
Host: api.example.com              (25 bytes)
Authorization: Bearer eyJhbG...    (50+ bytes)
Accept: application/json           (20 bytes)
Content-Type: application/json     (25 bytes)
                                  ─────────
Total: ~120 bytes (sent EVERY request)

HTTP/2 Headers (HPACK compressed):
First request: Full headers (~120 bytes)
Subsequent:    Only changed headers (~10-20 bytes)

Server Push

Client requests: GET /index.html

Without Push:
1. GET /index.html → Response
2. GET /style.css → Response
3. GET /app.js → Response
(Total: 3 round trips)

With Push:
1. GET /index.html
2. Server pushes: /style.css, /app.js
3. All arrive together
(Total: 1 round trip)

HTTP/2 in Practice

Enabling HTTP/2

Nginx:

server {
    listen 443 ssl http2;
    server_name api.example.com;
    # HTTP/2 automatically enabled with SSL
}

Spring Boot:

# application.properties
server.http2.enabled=true

HTTP/2 Priority

Streams can be prioritized:

Stream 1 (High Priority): /critical-api/data
Stream 2 (Low Priority):  /analytics/event
Stream 3 (Medium):        /user/profile

Server allocates bandwidth based on priority

When HTTP/2 Helps Most

Scenario Improvement
Many small requests Multiplexing eliminates connection overhead
Large headers HPACK compression reduces size
Page with many resources Server push reduces round trips
Mobile connections Fewer connections = less battery drain

Practice Problems

0/3solved
Implement HTTP/2

Design and implement a solution for HTTP/2 in a backend system. Consider scalability, error handling, and production readiness.

Solution
// HTTP/2 implementation
// Key aspects: validation, error handling, logging, testing

public class HTTP2 {
    // Production-ready implementation
}
HTTP/2 Edge Cases

Identify and handle edge cases for HTTP/2. What happens under high load, with invalid input, or during failures?

Solution
// Edge case handling:
// 1. Null/empty input -> validation
// 2. High load -> rate limiting, queuing
// 3. Failures -> retries, circuit breaker
// 4. Concurrent access -> locks, idempotency
HTTP/2 Testing Strategy

Write a testing strategy for HTTP/2. Include unit tests, integration tests, and performance tests.

Solution
// Test plan:
// - Unit: 80% coverage target
// - Integration: API contracts
// - Performance: latency, throughput
// - Chaos: failure injection

Quiz

1. What problem does HTTP/2 multiplexing solve?

Question 1 options

2. What compression does HTTP/2 use for headers?

Question 2 options

3. What is HTTP/2 server push?

Question 3 options

4. What is the primary purpose of HTTP/2?

Question 4 options

Flashcards

Question

What is HTTP/2 multiplexing?

Answer

Multiple requests/responses interleaved on a single TCP connection

Question

What is HPACK?

Answer

Header Compression for HTTP/2 — reduces header size across requests

Question

What is HTTP/2?

Answer

HTTP/2 is a key concept in backend development.

Question

When to use HTTP/2?

Answer

Use HTTP/2 when building production systems that require reliability, scalability, and maintainability.

Question

HTTP/2 best practices

Answer

Follow SOLID principles, write clean code, test thoroughly, document decisions, and monitor in production.

Revision Notes

Key Takeaways

  • 1.HTTP/2 multiplexing eliminates head-of-line blocking
  • 2.HPACK compresses headers across requests
  • 3.Server push proactively sends predicted resources
  • 4.HTTP/2 requires TLS (in practice)

Interview Tips

  • Explain how multiplexing improves performance
  • Know the difference between HTTP/1.1 and HTTP/2

Cheat Sheet

HTTP/2

  • Multiplexing: Multiple requests on one connection
  • HPACK: Header compression
  • Server Push: Proactively send resources
  • Requires: TLS (in practice)
  • vs HTTP/1.1: Eliminates HOL blocking