Internal Verification Endpoint (Security)
Description
Create a high-performance internal endpoint for inter-service communication. This endpoint is designed to be called frequently by the Chat Service and other microservices to verify friendship status between two users.
Objectives
1. GET /internal/status/:user1/:user2
Returns the friendship status between two users with optimized performance.
Requirements:
- Return friendship status between user1 and user2
- Endpoint is for internal service-to-service communication only
- Optimize for speed (high-frequency calls from Chat Service)
- Implement caching strategy for performance
- Validate both user IDs exist before querying
- Handle bidirectional friendship relationships
Path Parameters:
user1 (UUID): First user ID
user2 (UUID): Second user ID
Response (200 OK):
{
"user1": "user-id-1",
"user2": "user-id-2",
"status": "FRIENDS",
"isFriends": true
}
Alternative Response (when not friends):
{
"user1": "user-id-1",
"user2": "user-id-2",
"status": "PENDING",
"isFriends": false
}
Possible Status Values:
FRIENDS: Both users are friends
PENDING: A friendship request is pending
NONE: No friendship relationship exists
BLOCKED: One user has blocked the other
Error Cases:
- 400: Invalid user ID format
- 404: One or both users not found
- 500: Internal server error
Security Requirements
Authentication & Authorization
Data Protection
Performance Optimization
Caching Strategy
- Implement Redis caching with TTL (Time To Live)
- Cache key format: internal: friendship:{user1}:{user2}
- Cache TTL: 5-15 minutes (configurable)
- Invalidate cache on friendship status changes
- Support cache bypass parameter for fresh data (internal use only)
Database Optimization
Response Time Target
Implementation Details
Cache Invalidation Strategy
When status changes (POST /friends/request, PATCH /friends/accept):
- Invalidate cache for both directions:
- internal:friendship:{user1}:{user2}
- internal:friendship:{user2}:{user1}
Example Usage (Chat Service)
GET /internal/status/user-123/user-456
Response: { status: "FRIENDS", isFriends: true }
Chat Service Logic:
if (isFriends) {
allowMessage();
} else {
blockMessage();
}
Integration Points
Services Using This Endpoint
Metrics & Monitoring
Acceptance Criteria
Additional Notes
- Consider implementing a request/response compression if dealing with high volume
- Monitor cache efficiency and adjust TTL based on usage patterns
- Consider implementing a GraphQL query for multiple status checks in one request (future optimization)
- Document rate limit thresholds for internal services
- Plan for graceful degradation if cache is unavailable
Internal Verification Endpoint (Security)
Description
Create a high-performance internal endpoint for inter-service communication. This endpoint is designed to be called frequently by the Chat Service and other microservices to verify friendship status between two users.
Objectives
1. GET /internal/status/:user1/:user2
Returns the friendship status between two users with optimized performance.
Requirements:
Path Parameters:
user1(UUID): First user IDuser2(UUID): Second user IDResponse (200 OK):
{ "user1": "user-id-1", "user2": "user-id-2", "status": "FRIENDS", "isFriends": true }Alternative Response (when not friends):
{ "user1": "user-id-1", "user2": "user-id-2", "status": "PENDING", "isFriends": false }Possible Status Values:
FRIENDS: Both users are friendsPENDING: A friendship request is pendingNONE: No friendship relationship existsBLOCKED: One user has blocked the otherError Cases:
Security Requirements
Authentication & Authorization
Data Protection
Performance Optimization
Caching Strategy
Database Optimization
Response Time Target
Implementation Details
Cache Invalidation Strategy
Example Usage (Chat Service)
Integration Points
Services Using This Endpoint
Metrics & Monitoring
Acceptance Criteria
Additional Notes