API Overview
The User Service exposes RESTful endpoints for managing users and their email addresses. All endpoints require authentication via Cognito JWT tokens. Base URL:https://api.example.com/v1
User Endpoints
Get Current User
Retrieve the authenticated user’s profile.Returns the current user’s profile data.
Update Current User
Update the authenticated user’s profile.Updates profile fields. Partial updates supported.
Delete Current User
Soft-delete the authenticated user’s account.Sets user status to
deleted. Does not remove data.Soft delete is used to maintain referential integrity. Downstream services receive a
user.deleted event to handle cleanup (cancel pending bookings, final invoices, etc.).Email Endpoints
List User Emails
Get all email addresses for the current user.Returns all emails associated with the user.
Add Email
Add a new email address to the user’s account.Adds a new email. Verification required before use.
Delete Email
Remove an email address from the user’s account.Removes the specified email.
Request Verification
Send a verification code to an unverified email.Sends verification code. Rate limited.
Confirm Verification
Confirm email ownership with verification code.Confirms the verification code.
Set Primary Email
Set an email as the user’s primary email address.Designates this email as primary.
Edge Cases
Cannot Delete Primary Email
Scenario: User tries to delete their primary email. Handling:Cannot Delete Last Email
Scenario: User tries to delete their only email address. Handling:Duplicate Email
Scenario: User tries to add an email that’s already in use (by them or another user). Handling:Unverified Email as Primary
Scenario: User tries to set an unverified email as primary. Handling:Verification Rate Limiting
Scenario: User requests too many verification codes. Handling:- 3 verification requests per email per hour
- 5 confirmation attempts per code
Rate Limiting Implementation
Rate limiting in a serverless context requires stateful tracking. Here’s how to implement it.Strategy: DynamoDB Token Bucket
DynamoDB is used to track request counts per user/email with TTL for automatic cleanup. Rate Limit Table Schema:
Implementation:
Alternative: API Gateway Usage Plans
For API-wide rate limiting (not user-specific):Rate Limit Headers
All rate-limited endpoints return standard headers:Concurrent Update Conflict
Scenario: Two requests update the same user simultaneously. Handling:Request Validation
Email Format
Phone Format
Name Fields
Error Response Format
All errors follow a consistent format:requestId enables correlation with CloudWatch logs for debugging.