SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

SSL/TLS

The handshake and encryption that keep a connection private and prove who you are talking to.

⏱ 15 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

TLS (Transport Layer Security) is the protocol that makes a connection private and proves who you are talking to. It is the "S" in HTTPS. SSL is its old name, and today everyone really uses TLS.

  • Encryption: people on the network see only scrambled bytes.
  • Authentication: a certificate proves the server is really the site you asked for.
  • Integrity: any change to the data in transit is detected.

02Concept: What is it?

Plain HTTP sends everything as readable text. Anyone on the same Wi-Fi, or on any machine along the route, can read your password or change the page. TLS adds a protective layer between your app (HTTP) and the network (TCP). HTTP over TLS is called HTTPS.

TLS uses two kinds of cryptography together. Asymmetric cryptography (key pairs) is used in the handshake to agree on a secret and to prove identity, but it is slow. Symmetric cryptography (one shared key) is used for the actual data, because it is very fast.

Identity comes from certificates. A certificate says "this public key belongs to shop.example.com" and is signed by a Certificate Authority (CA) that browsers already trust. The server proves it owns the certificate by signing the handshake with the matching private key.

Before and after TLS
Plain HTTP
πŸ’»Browser
→↓password=hunter2
πŸ–₯️Server
πŸ‘€Anyone on the pathreads and edits it
HTTPS (TLS)
πŸ’»Browser
→↓a9 4f 03 d7 ...
πŸ–₯️Server
πŸ”’Anyone on the pathsees noise only
With TLS, a person on the path sees only scrambled data, and the browser knows it reached the real site.
🧠Three promises
Privacy (nobody can read it), identity (you reached the real server) and integrity (nobody changed it on the way).

03Real-Life Example

🍡The Sealed Letter and the Passport Check
You want to send a private letter to a bank. First you need to be sure you are writing to the real bank, not a thief's office with the same sign. The bank shows a passport issued by the government (a certificate signed by a trusted CA). You check that the photo and the name match, and that the passport has not expired. Then you and the bank agree on a secret code in a way that a person watching you cannot learn it, and from then on all letters are written in that code.
Letter to the bank
TLS
Passport
Server certificate
The government that issued it
Certificate Authority (CA)
Checking the photo and name
Checking the certificate name matches the site
Checking the expiry date
Checking the certificate's valid dates
Agreeing on a secret code in public, safely
Key exchange (Diffie-Hellman)
Writing every letter in the code
Symmetric encryption of the data
A forged or out-of-date passport
Browser warning, connection stopped
The handshake in short (TLS 1.3)
πŸ‘‹Helloversions, ciphers, key share
→↓
πŸͺͺProve identitycertificate + signature
→↓
πŸ”‘Shared keysderived on both sides
→↓
πŸ”’Encrypted datafast symmetric

04Why Do We Need It?

πŸ•΅οΈStop eavesdropping
Passwords, cards and messages cannot be read on public Wi-Fi or by anyone along the route.
🎭Stop impostors
The certificate check makes sure you reached the real site, not a fake copy.
✏️Stop tampering
Ads, malware or changed prices cannot be slipped into the page in transit.
πŸ“œRules and trust
Standards such as PCI DSS and HIPAA expect encryption in transit, and browsers mark plain HTTP as not secure.
πŸš€Newer web features
HTTP/2, HTTP/3 and many browser APIs (service workers, geolocation) need a secure connection.
πŸ”ŽSearch and user trust
Users and search engines prefer HTTPS sites.
Anything that crosses a network you do not control should be encrypted and authenticated. TLS is how that is done on the web.

05Where Do We Use It?

🌐Websites and APIs
Every public web page and API should be HTTPS only.
βš–οΈAt the load balancer
Many systems end (terminate) TLS at the load balancer or CDN, and use plain or re-encrypted traffic inside.
πŸ”—Between services (mTLS)
Both sides show certificates, so each service knows who is calling. Service meshes automate this.
πŸ—„οΈDatabases and queues
Connections to PostgreSQL, Redis and Kafka can use TLS too.
πŸ“§Email and other protocols
SMTP, IMAP, FTP and MQTT can all be wrapped in TLS.
πŸ”ŒVPNs and mobile apps
Apps validate server certificates, and some pin them for extra safety.

06Types / Parts / How It Works

The pieces

PieceWhat it doesPlain meaning
CertificateBinds a public key to a site name, with valid dates, signed by a CAThe server's passport
Private keyStays secret on the server. Used to sign the handshake.Proof that you own the passport
Certificate Authority (CA)A trusted organisation that signs certificates after checking the ownerThe passport office
Chain of trustSite certificate, signed by an intermediate CA, signed by a root CA in the browser's trust storeA chain of signatures back to someone you trust
Key exchange (ECDHE)Both sides create a one-time secret using ephemeral key pairsAgreeing a code in public
Cipher suiteThe set of algorithms used (key exchange, encryption, hashing)The agreed list of tools
SNIThe browser names the site in the first message, so one IP can host many sitesWhich door you are knocking on

Chain of trust

How a browser trusts a certificate
🌐shop.example.comsite certificate
↑signed by
🏒Intermediate CAsent by the server
↑signed by
πŸ›οΈRoot CAalready trusted by the browser
The server sends the first two. The root is already inside the browser or operating system.

TLS 1.2 and TLS 1.3

TLS 1.2TLS 1.3
Handshake round trips21 (and 0-RTT resumption, with some replay risk)
Forward secrecyOnly if an ephemeral cipher suite (ECDHE) is chosenAlways
Old, weak optionsMany are still allowed (RC4, CBC modes, static RSA key exchange)Removed
Certificate visible to observersYesNo, it is encrypted
TodayStill common, acceptable when configured wellPreferred
πŸ“Note
SSL 2.0, SSL 3.0, TLS 1.0 and TLS 1.1 are obsolete and should be turned off. People still say "SSL certificate", but the connection uses TLS.

Where TLS ends

Three common setups
Terminate at the edge
πŸ’»Client
→↓TLS
βš–οΈLoad balancer
⇒⇣plain
πŸ–₯️App
Re-encrypt
πŸ’»Client
→↓TLS
βš–οΈLoad balancer
→↓TLS
πŸ–₯️App
mTLS between services
πŸ–₯️Service Ahas a certificate
↔both prove identity
πŸ–₯️Service Bhas a certificate
Choose by who must be protected, and how much work you can accept.
VisualizerStep through a TLS handshake, and see what goes wrongPress Next to walk through the handshake. Switch between TLS 1.3 and 1.2 and watch the round trips change. Then try an expired certificate, a wrong name, an unknown issuer, and plain HTTP.
What does the browser meet?
TLS version
πŸ’»Browser
↔TCP connect (1 round trip)
πŸ–₯️Server
Step 1 of 6
Open the connection (TCP)
First the usual TCP handshake. This costs one round trip before any TLS message can be sent.
What a person on the cafΓ© Wi-Fi sees of the login request
a9 4f 03 d7 5c e1 88 2b 7e 90 b4 16 f2 6d 31 c8 ...
The site name (SNI) may still be visible, unless the browser and server use Encrypted Client Hello.
Round trips before the request
2
1 TCP + 1 TLS
Time to first byte
240 ms
3 round trips x 80 ms
Private?
Yes
can others read it
Proves identity?
Yes
is it really the site

A simplified model: it counts network round trips only and ignores computing time, packet loss and TLS features such as session resumption. Real set-up time depends on the route and the servers.

07How to Use It / Steps / Implementation

Using TLS well

  1. 1
    Get a certificate for your domain
    Use a public CA (for example Let's Encrypt or your cloud provider) for public sites. They check you control the domain first.
  2. 2
    Install the chain, not only the leaf
    The server must also send the intermediate certificate, or some clients will fail to build the chain.
  3. 3
    Allow TLS 1.2 and 1.3 only
    Turn off SSL 3.0, TLS 1.0 and TLS 1.1, and disable weak cipher suites. Prefer 1.3.
  4. 4
    Redirect HTTP to HTTPS
    Then add the HSTS header, so browsers use HTTPS from the first request next time.
  5. 5
    Automate renewal
    Certificates expire. Use ACME (for example certbot) or a managed service, and alert well before the expiry date.
  6. 6
    Protect the private key
    Never put it in git or an image. Keep it in a secrets manager or a managed service and limit who can read it.
  7. 7
    Use mTLS between internal services when needed
    A service mesh can issue and rotate short-lived certificates for you.
  8. 8
    Test the setup
    Run a scanner such as SSL Labs, and check the chain, protocol versions and expiry. Test again after changes.
πŸ’‘Short-lived certificates are friendlier
Public certificates already have short lifetimes, and the trend is shorter still. If renewal is automatic, a short lifetime limits the damage of a stolen key and removes the "someone forgot to renew" outage.
⚠️Never turn off verification to make an error go away
Setting "insecure skip verify" in a client makes the error disappear, and removes the identity check. An attacker in the middle can now pose as the server. Fix the certificate or add the right CA instead.

08Key Terms to Know

TermMeaning in easy words
TLSTransport Layer Security: the protocol that encrypts and authenticates connections
SSLThe old name and the older versions of TLS. Obsolete, but the name stuck.
HTTPSHTTP carried over TLS
CertificateA signed document that links a public key to a site name
Certificate Authority (CA)A trusted organisation that signs certificates
Chain of trustThe line of signatures from the site certificate up to a trusted root
HandshakeThe opening exchange where both sides agree on keys and the server proves its identity
Symmetric encryptionOne shared key encrypts and decrypts. Fast, used for the data.
Asymmetric encryptionA public and private key pair. Slower, used for identity and key agreement.
Forward secrecyPast traffic stays safe even if the server's long-term private key is stolen later
mTLSMutual TLS: the client also shows a certificate, so both sides are authenticated
SNIServer Name Indication: the site name the browser sends, so one IP can serve many sites
HSTSA header that tells browsers to use only HTTPS for your site

09Pros, Cons and Trade-offs

βœ… Pros
  • Private connections that others cannot read
  • Proof that you reached the real server
  • Detects changes made in transit
  • Required by browsers, standards and many features
  • Mature, well-supported and widely automated
⚠️ Cons
  • Extra round trips and some CPU for each new connection
  • Certificates must be issued, renewed and kept safe
  • Expired or wrong certificates cause outages
  • Encrypted traffic is harder to inspect for debugging and security tools
  • Misconfiguration can still leave weak options on

Trade-offs

ChoiceWe gainWe lose
Terminate TLS at the load balancerOne place to manage certificates, less CPU on the appTraffic inside is not protected unless re-encrypted
Re-encrypt to the backendProtected end to end inside the networkMore certificates and more CPU
mTLS between servicesStrong service identity, no network trust assumedMore set-up (a CA, rotation); a mesh usually handles it
Short-lived certificatesA stolen key is useful only brieflyNeeds reliable automation
Long-lived certificatesFewer renewalsA forgotten expiry is an outage, and a stolen key lasts longer
TLS 1.3 onlyFastest and safestVery old clients cannot connect

10Common Problems and Mistakes

Common mistakes

  1. Expired certificates. A classic cause of outages. Automate renewal and alert early.
  2. Missing intermediate certificate. It works in your browser (which caches it) and fails in other clients.
  3. Name mismatch. The certificate covers www.example.com but not example.com or a new subdomain.
  4. Turning off verification. "Skip verify" in a client removes the main protection.
  5. Mixed content. An HTTPS page that loads scripts or images over HTTP is only partly protected, and browsers may block it.
  6. Old protocol versions. Leaving TLS 1.0 or weak ciphers on for "compatibility".
  7. Leaked private key. Stored in git or an image. Replace the certificate and key at once.

Things to watch

⏰Expiry dates
Track every certificate, including internal ones and those on third-party services.
πŸ”Rotation
Rotate keys on a schedule and after any suspected leak.
⚑Handshake cost
Reuse connections (keep-alive, HTTP/2) and use session resumption so you do not pay the handshake every time.
πŸ•³οΈDowngrade attacks
HSTS and disabling old versions stop an attacker from forcing a weaker connection.

11Real-World Examples

πŸ”Free automatic certificates
Let's Encrypt issues free certificates using the ACME protocol, which made HTTPS everywhere easy.
☁️Cloud load balancers and CDNs
Cloud providers and CDNs terminate TLS at the edge and manage certificates for you.
πŸ•ΈοΈService meshes
Meshes such as Istio and Linkerd give each workload a short-lived certificate and turn on mTLS between services.
🏦Banks and payments
Card and banking systems must encrypt data in transit, and some partner links use mTLS.
πŸ“±Mobile apps
Apps verify server certificates, and some pin the expected key to resist a bad CA.
πŸ”₯Expiry outages
Many well-known services have gone down because a certificate expired and nobody renewed it.
πŸ“Note
Browser and CA rules (such as maximum certificate lifetime) change over time. Check current guidance before you plan renewals.
Mini case: a safe public API
πŸ“±Mobile app
→↓TLS 1.3
βš–οΈGatewaypublic certificate
→↓mTLS
πŸ–₯️Orders serviceshort-lived certificate
Client Edge Inside
Edge TLS for users, mTLS inside, and a secrets manager for keys.

12Related Topics to Read Next

HTTP / HTTPS→

HTTPS is HTTP carried over TLS.

Encryption at Rest→

TLS protects data moving, this protects data stored.

Secrets Management→

Where private keys and certificates should be kept.

Service Mesh→

Automates mTLS and certificate rotation between services.

What are Load Balancers?β†’

A common place to terminate TLS.

Authentication vs Authorization→

TLS proves the server; logins prove the user.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”TLS: privacy, identity and integrity for a connection. HTTPS is HTTP over TLS.
  • βœ”SSL: the old name. Turn off SSL 3.0, TLS 1.0 and 1.1.
  • βœ”Handshake: hello and key share, certificate and signature, shared keys, then encrypted data.
  • βœ”Two kinds of crypto: asymmetric for identity and the key exchange, symmetric for the data.
  • βœ”Certificate check: trusted chain, right name, valid dates.
  • βœ”TLS 1.3: one round trip, always forward secrecy, weak options removed.
  • βœ”Operations: automate renewal, send the full chain, guard the private key, never skip verification.
  • βœ”One line: β€œProve who you are, agree on a secret, then lock everything with it.”
← Previous
Audit Logs
Next β†’
Encryption at Rest