0
0
Nginxdevops~5 mins

HSTS header in Nginx - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: HSTS header
O(n)
Understanding Time Complexity

We want to understand how adding the HSTS header affects nginx's work as requests come in.

Specifically, how does the server's effort change as more requests arrive?

Scenario Under Consideration

Analyze the time complexity of the following nginx configuration snippet.

server {
    listen 443 ssl;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    # other config...
}

This snippet adds the HSTS header to every HTTPS response to tell browsers to use HTTPS only.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Adding the HSTS header to each HTTPS response.
  • How many times: Once per HTTPS request received by the server.
How Execution Grows With Input

Each new HTTPS request causes nginx to add the HSTS header once.

Input Size (n)Approx. Operations
1010 header additions
100100 header additions
10001000 header additions

Pattern observation: The work grows directly with the number of requests.

Final Time Complexity

Time Complexity: O(n)

This means the server's work to add the HSTS header grows linearly with the number of HTTPS requests.

Common Mistake

[X] Wrong: "Adding the HSTS header slows down the server exponentially as requests increase."

[OK] Correct: Adding a header is a simple step done once per request, so the work grows steadily, not exponentially.

Interview Connect

Understanding how simple configuration changes affect server work helps you explain performance impacts clearly and confidently.

Self-Check

"What if we added multiple headers instead of just one? How would the time complexity change?"