Overview
The CallerService acts as a proxy to external HTTP APIs, providing a gRPC interface for making HTTP GET requests. This service demonstrates asynchronous database logging and timeout handling patterns. Base Path:/caller.v1.CallerService
Authentication: Not required (internal service)
Middleware: None (internal-only access)
RPCs
CallExternal
Makes an HTTP GET request to a specified URL and returns the status code and response body length. Call logs are asynchronously written to the database. Endpoint:POST /caller.v1.CallerService/CallExternal
Signature:
Request
The target URL to call. Must be a valid HTTP/HTTPS URL. The service will perform a GET request to this endpoint.Example:
https://httpbin.org/getResponse
The HTTP status code returned by the external API
The size of the response body in bytes
Go Client Example
cURL Example (h2c)
Example Response
Implementation Details
Database Integration
The CallExternal RPC performs an asynchronous database write to thecall_logs table:
- ✅ Lower latency: Response is returned immediately without waiting for the database
- ⚠️ Potential log loss: If the database write fails, the log entry may be lost (error is only logged)
HTTP Client Configuration
- Timeout: 2 seconds per HTTP request
- Method: GET only
- Response handling: Body is discarded after reading (only length is tracked)
Error Handling
The service returns Connect RPC error codes:| Error Code | Condition |
|---|---|
CodeInvalidArgument | Invalid URL format |
CodeDeadlineExceeded | HTTP request timeout (2 seconds) |
CodeUnavailable | Network error or target unreachable |
CodeInternal | Failed to build request or read response |
URL Validation
The service validates that the provided URL is a valid HTTP/HTTPS URI using Go’surl.ParseRequestURI(). URLs that fail validation will return CodeInvalidArgument.
Service Architecture
Internal-Only Access
The CallerService is designed as an internal service and is not exposed through the Traefik ingress. It can only be accessed by other services within the Kubernetes cluster:- Default endpoint:
http://caller-service.microservices:8081 - No authentication required (relies on network isolation)
Service Dependencies
- PostgreSQL: Stores call logs in the
caller_db.call_logstable (optional) - External APIs: Makes HTTP GET requests to user-specified URLs
Timeouts
- HTTP request timeout: 2 seconds
- HTTP client timeout: 2 seconds
- RPC context timeout: 2 seconds (enforced by caller)
Database Schema
The service logs calls to the following table structure:Service Configuration
| Environment Variable | Default | Description |
|---|---|---|
PORT | 8081 | Service port |
DATABASE_URL | - | PostgreSQL connection string (optional) |
OTEL_EXPORTER_OTLP_ENDPOINT | - | OpenTelemetry collector endpoint |
Observability
The CallerService is instrumented with OpenTelemetry for distributed tracing:- HTTP calls are traced with span attributes
- Errors are recorded as span events
- Service metrics include request duration and error rates
Common Use Cases
- External API Integration: Use CallerService as a proxy for external HTTP APIs with built-in logging
- Health Checks: Check external service availability
- Data Fetching: Retrieve data from external sources with automatic retry and timeout handling