Clean • Professional
In modern applications and microservices architectures, APIs are the backbone of communication. However, not all APIs are the same. Some are internal, used exclusively for service-to-service communication within an organization, while others are public, exposed to external clients, mobile apps, or third-party integrations.
Each type requires distinct security strategies to protect data, prevent abuse, and maintain service integrity.
Internal APIs are private interfaces used for communication within an organization, primarily between microservices, backend systems, or internal applications. Unlike public APIs, they are not exposed to external users, but still require strong security to protect against insider threats, compromised services, or lateral attacks.
Examples of Internal APIs:
Key Security Measures for Internal APIs:
1. Mutual TLS (mTLS)
2. JWT Token Relay
3. Least-Privilege Access
4. Segmentation & Network Policies
5. Monitoring & Auditing
Public APIs are interfaces exposed to external clients, partners, or third-party applications. Since they are accessible over the internet, they are more vulnerable to attacks and require strong security measures to protect sensitive data, maintain service availability, and prevent abuse.
Examples of Public APIs:
Essential Security Measures for Public APIs:
1. Authentication & Authorization
2. Rate Limiting & Throttling
3. Traffic Encryption
4. Input Validation & Request Filtering
5. Monitoring & Logging
| Feature | Internal APIs | Public APIs |
|---|---|---|
| Access | Trusted internal services within the organization | External clients, partners, or third-party users |
| Security Focus | Authentication and authorization between services | Strong access control, rate limiting, and active monitoring |
| Exposure | Private network or cloud infrastructure | Internet-facing endpoints accessible to anyone |
| Encryption | Optional TLS/mTLS within internal network | Mandatory HTTPS/TLS for all external traffic |
| Rate Limiting | Moderate; based on service load and trust | Strict limits to prevent abuse, DoS attacks, and overloading |
| Logging & Auditing | Focus on internal compliance and troubleshooting | Regulatory reporting, monitoring for suspicious activity, and external visibility |
Securing APIs is critical to protect sensitive data, maintain service reliability, and prevent unauthorized access. The strategies differ for internal versus public APIs based on exposure and risk.
Internal APIs
Public APIs
Demonstrates encrypted and authenticated communication between microservices using mTLS while preserving user identity via JWT token relay.
Server Configuration (Spring Boot):
server:
port: 8443
ssl:
key-store: service-keystore.p12
key-store-password: changeit
trust-store: truststore.p12
trust-store-password: changeit
Client Configuration (WebClient):
@Bean
public WebClient webClient() throws Exception {
SslContext sslContext = SslContextBuilder.forClient()
.trustManager(new File("truststore.p12"))
.keyManager(new File("client-keystore.p12"), "changeit")
.build();
HttpClient httpClient = HttpClient.create()
.secure(sslSpec -> sslSpec.sslContext(sslContext));
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
}
Flow Example:
Client App → API Gateway → Service A → Service B → Service C
Highlights:
Shows how external client requests are secured with JWT authentication and protected against abuse with rate limiting and monitoring.
Spring Cloud Gateway Configuration:
spring:
cloud:
gateway:
routes:
- id: public-api
uri: lb://public-service
predicates:
- Path=/api/public/**
filters:
- RequestRateLimiter: # Limit requests per client
- TokenRelay: # Forward validated JWTs
Internal APIs:
Public APIs:
Securing internal and public APIs requires different strategies:
By implementing these practices, organizations can ensure secure, scalable, and resilient API ecosystems that protect sensitive data and maintain reliable service operations.