Design: API Key Management System
Design covers API key lifecycle management, validation, and usage tracking. Does not cover full user authentication or billing systems.
Functional Requirements
Non-Functional Requirements
+-------------------+ +-----------------------+ +------------------+
| | | | | |
| API Gateway / | <---> | API Key Management | <---> | Database (SQL/NoSQL) |
| Auth Service | | Service | | |
| | | | | |
+-------------------+ +-----------------------+ +------------------+
| | |
| | |
v v v
+-------------------+ +-----------------------+ +------------------+
| | | | | |
| Cache (Redis) | | Rate Limiter | | Audit Logging |
| | | | | Service |
+-------------------+ +-----------------------+ +------------------+API-Key or similar, but Authorization: Bearer is usually for tokens, not API keys.API-Key is the widely accepted header for API keys, making API-Key: <API_KEY> correct.API-Key: <API_KEY> -> Option Cfunction validateKey(request) {
key = request.headers['API-Key']
if key is null or key not in validKeys:
return 'Access Denied'
else:
return 'Access Granted'
}
What will be the output if the request has no 'API-Key' header?function revokeKey(key) {
if key in activeKeys:
activeKeys.remove(key)
else:
print('Key not found')
}
But the key is still accepted after revocation. What is the likely issue?Pass the test and this pattern moves unknown