← cd ../blog
tls-vs-end-to-end-api-encryption.md
·10 min read

TLS vs End-to-End API Encryption: How It Works, Why, and When It Matters

#Security#FinTech#Encryption#Backend

Disclaimer: This article is intended for a technical audience.

I recently had a conversation with an engineer who argued that end-to-end API encryption is over-engineering. After all, HTTPS already provides a widely trusted encryption system via TLS, and adding encryption at the application layer of the OSI model could introduce additional latency overhead. Considering that he is predominantly a frontend engineer and has limited experience building enterprise-grade financial applications, I understand his point. For most applications on the World Wide Web, TLS is more than sufficient.

However, my perspective is slightly different, and it comes from years of building enterprise-grade applications that handle people's money, personal data, and sensitive financial information. In these scenarios, security and user privacy take precedence over low latency or minor performance gains.

When I built my first "Hello World" application, there was no need for end-to-end encryption. Implementing it at that stage would have been unnecessary complexity and clear over-engineering. Based on my experience and interaction with engineers in other industries, I have observed that the type of solution you are building, the industry you operate in, and the nature of the data you handle fundamentally shape your decisions around encryption and security.

So while TLS protects data in transit, there are scenarios, especially in financial systems, where end-to-end encryption is not over-engineering. Instead, it is a deliberate layer of defense designed to protect users even when traffic passes through multiple intermediaries. That is the lens through which I am writing this article. If you have engaged in similar conversations, or if you build data-intensive applications such as financial systems, you will likely find valuable insights here. Enjoy.

Let Me Quickly Explain TLS Encryption Without Publishing a Textbook

If security is a fortress, TLS (Transport Layer Security) is the high-voltage perimeter fence. It is the backbone of secure communication on the internet. When you see that padlock (as shown below in Fig. 1) in your browser, TLS is the engine under the hood ensuring that your data isn't being read by a nosy neighbor or a malicious ISP (Internet Service Provider) while it's in transit.

Fig. 1 — The TLS padlock in your browser
Fig. 1 — The TLS padlock in your browser

How it works

In the academic world of the OSI (Open System Interconnection) Model, TLS is a bit of a nomad. While many textbooks place it at the Presentation Layer (Layer 6) because it handles encryption and decryption, it actually straddles several layers:

  • Layer 5 (The session layer): It manages the "handshake" (trust establishment), the initial "Hello" where the client and server agree on how they are going to talk.
  • Layer 4 (The transport layer): It works directly on top of TCP to ensure the entire stream of data is secure from end to end.

TLS uses Asymmetric Cryptography (Public/Private keys) to perform a digital handshake. Once the identities are verified, it negotiates a Symmetric Session Key. This session key is what encrypts the actual data flow. It's fast, it's efficient, and it's why the modern web is possible.

The "Termination" Trap: A Tale of Two Pipes

To the user sitting at home, the connection is secure. They see the padlock, and they feel safe. But as a backend engineer, you have to look at the entire lifecycle of the data, not just the wire. In an enterprise cloud architecture (think AWS, Azure, or GCP), the journey of a request is actually split into two distinct "pipes":

The Public Pipe (Client → API Gateway/Load Balancer): This is the part most frontend engineers are exposed to. It is encrypted via TLS. This protects the data from man-in-the-middle attacks. Within this pipe, the data is safe from external eavesdropping.

The Private Pipe (API Gateway/Load Balancer → Internal Server): This is where TLS termination happens. Most load balancers (LBs) or API gateways perform TLS termination. They decrypt the packet so they can inspect headers, manage cookies, or perform Layer 7 routing. Once the LB or gateway is done, it often sends the request to your internal microservices or backend servers in plaintext over the internal network.

If your engineer says "HTTPS is enough," they are assuming two things that are rarely true in a high-stakes environment:

First, they assume the internal network is 100% secure. In a zero-trust industry, we assume the internal network is already compromised. If an attacker gains a foothold in one minor internal service, they can listen to plaintext banking traffic flowing from the load balancer to the core banking application.

Second, they overlook proxy-based tampering. Even if the pipe is secure, the sender can still be the attacker. An attacker can install a root certificate on their own device and use a tool like Burp Suite to man-in-the-middle themselves. With TLS only, the attacker sees the decrypted request in their proxy, changes "amount": 100 to "amount": 1000000, and sends it. The load balancer or gateway accepts it because the TLS connection is valid.

With end-to-end encryption, the attacker sees only gibberish. They cannot locate or modify the amount field because the payload is encrypted at the application layer before it ever enters the TLS pipe.

TLS secures the connection between two points. End-to-end encryption secures the message regardless of the connection.

End-to-End API Encryption: The Extra Layer

If TLS is the armored truck, end-to-end encryption (E2EE) is the locked safe inside that truck. E2EE ensures that only the intended recipient, the application code, can decrypt the payload. This keeps the data secure even as it passes through various pipelines.

How it Works

Unlike TLS, which operates across lower layers, E2EE operates squarely at the application layer (Layer 7). We are no longer encrypting the connection; we are encrypting the actual JSON or XML payload itself.

The most common approach is a hybrid cryptography model:

  • Asymmetric Encryption (RSA/ECC): Used for the initial handshake to securely exchange a secret key between the client and the server.
  • Symmetric Encryption (AES-256): Used to encrypt the actual request and response payloads. It is fast and provides high-level security for the bulk of the data.
  • PGP (Pretty Good Privacy): More complex to implement and largely used by legacy systems. Often used for batch processing. For example, sending a 2 GB settlement file to a central bank, where data protection at rest and digital signatures for non-repudiation are required.

Advantages of E2EE

  • Neutralizing the Termination Trap: Because encryption happens in application code before transmission, the payload remains encrypted through load balancers and internal networks.
  • Insider Threat Mitigation: It protects against curious administrators. Whether it is a DBA or a DevOps engineer inspecting traffic in tools like Kong or Apigee, they see ciphertext, not PII or balances.
  • Tamper-Resistant Payloads: API tampering becomes significantly harder. Any modification to ciphertext causes decryption to fail and the request to be rejected.

Limitations of E2EE

  • Key Management Is Hard: Managing, rotating, and securing keys is complex. Losing a private key can lock you out of your own data.
  • The Black Box Problem: Intermediate systems such as WAFs or log aggregators cannot inspect encrypted payloads without custom decryption hooks.
  • Latency and Payload Size: Encryption adds CPU overhead, and Base64 encoding typically increases payload size by about 33%.

So, Is E2EE Over-Engineering?

If you are building a social media app for cat photos, yes. But if you are building the backend of an application that handles people's life savings, absolutely not.

The level of security you build should be determined by the depth of the risk you manage. In my world, user privacy and data integrity are the primary products. We do not just protect the pipe; we protect the payload. A lock is a promise of privacy to the user, and end-to-end encryption is one of the ways we keep that promise.

Final Note

Client-side encryption (end-to-end encryption) does not relieve backend services of their responsibility to validate requests. Security is not about doing one thing and declaring a system secure. No single mechanism makes an application immune to cyberattacks.

The goal is to create multiple layers of difficulty. End-to-end encryption, alongside authentication, authorization, payload validation, and IP whitelists or blacklists, strengthens your security architecture and significantly reduces the likelihood of a successful attack.

Thanks for reading.

# source publication

open source article →