SQS-powered usage log pipeline — fire-and-forget from the hot path, guaranteed delivery to Aurora via Lambda consumer.
During Run 17 stress testing (746,374 RPS, 1.34B requests), the in-process usage log writer's worker pool saturated under extreme load. Background work was silently shed — only ~12K usage_logs appeared in Aurora after 1.34 billion requests. The price response was never affected (0ms), but usage logging completeness was sacrificed.
Decouple usage logging from the hot path using SQS. The LPO server sends a fire-and-forget message to SQS for every price request. A purpose-built Go Lambda (trinity-beast-queued-writer) consumes batches from the queue and batch-inserts into Aurora. Zero logs shed. Zero latency added to the price response.
graph LR
Client["Client"] -->|"price request"| LPO["LPO Server"]
LPO -->|"0ms response"| Client
LPO -->|"fire-and-forget"| SQS["SQS Queue
trinity-beast-queued-usage-logs"]
SQS -->|"batch of 100"| Lambda["Lambda Consumer
trinity-beast-queued-writer"]
Lambda -->|"batch INSERT"| Aurora["Aurora
usage_logs table"]
Source: internal/database/sqs_producer.go
sqs_buffer_size parameter)SendMessageBatch (up to 10 per API call)Send() — if buffer full, message dropped (protects hot path)All messages use a standard envelope format. The type field routes processing in the Lambda consumer:
{
"type": "usage_log",
"timestamp": "2026-05-02T15:30:00.000Z",
"node": "BeastMain",
"payload": {
"api_key_id": "ak_live_abc123",
"asset": "BTC",
"source": "binance",
"response_time_us": 42,
"cache_tier": "L1_MEMORY"
}
}
type value and a corresponding handler case.
| Property | Value |
|---|---|
| Runtime | provided.al2023 (Go binary) |
| Memory | 256 MB |
| Routing | Routes on message type field |
| Write Strategy | Batch INSERT into Aurora |
| Side Effect | Updates current_usage counters per API key |
| Property | Value |
|---|---|
| Type | Standard (not FIFO — ordering not required for usage logs) |
| Message Retention | 4 days |
| Visibility Timeout | 60 seconds |
| Event Source Mapping — Batch Size | 100 |
| Event Source Mapping — Max Batching Window | 5 seconds |
All 4 SQS parameters are stored in the application_parameters table and are runtime-adjustable — no redeploy needed.
| Parameter | Default | Range | Purpose |
|---|---|---|---|
sqs_batch_size |
10 | 1–10 | Messages per SQS SendMessageBatch call |
sqs_flush_ms |
100 | >0 | Flush interval in milliseconds |
sqs_buffer_size |
50,000 | >0 | Channel buffer capacity before dropping |
sqs_timeout_ms |
3,000 | >0 | Per-batch SQS API call timeout |
application_parameters table — no redeploy needed. Changes take effect on the next flusher tick.
| Variable | Value | Set On |
|---|---|---|
SQS_USAGE_LOG_QUEUE_URL |
https://sqs.us-east-2.amazonaws.com/211998422884/trinity-beast-queued-usage-logs |
ECS task definitions |
DB_SECRET_NAME |
trinity-beast-secrets |
Lambda function |
The 4 SQS parameters are included in all 16 system profiles. Each profile tunes the queue behavior for its intended workload:
| Profile Category | SQSFlushMs | SQSBufferSize | Intent |
|---|---|---|---|
| Demo / Debug | 500 | 10,000 | Relaxed — low throughput, easy to observe |
| Production | 100 | 50,000 | Standard — balanced throughput and cost |
| Stress | 50 | 100,000 | Aggressive — maximum throughput for load testing |
| Scenario | Volume | Cost |
|---|---|---|
| Normal production | ~2.5M messages/month | ~$1/month |
| Stress test (746K RPS × 30 min) | 1.34B messages | ~$536 one-time |
| Lambda (256MB, ~50ms per batch) | Per million logs | Fractions of a cent |
The message envelope pattern supports future write types without infrastructure changes:
h.SQSProducer.Send("analytics_event", data) in any handlercase "analytics_event": in the Lambda consumertype field inside the message body.
// Producer side — any handler
h.SQSProducer.Send("analytics_event", AnalyticsPayload{
Event: "page_view",
Path: "/pricing",
UserID: session.UserID,
})
// Consumer side — Lambda handler
switch msg.Type {
case "usage_log":
batchInsertUsageLogs(msg.Payload)
case "analytics_event":
batchInsertAnalytics(msg.Payload)
}
ecsTaskRole)| Permission | Resource |
|---|---|
sqs:SendMessage |
arn:aws:sqs:us-east-2:211998422884:trinity-beast-queued-usage-logs |
sqs:SendMessageBatch |
arn:aws:sqs:us-east-2:211998422884:trinity-beast-queued-usage-logs |
trinity-beast-queued-writer-role)| Permission | Resource |
|---|---|
sqs:ReceiveMessage |
arn:aws:sqs:us-east-2:211998422884:trinity-beast-queued-usage-logs |
sqs:DeleteMessage |
arn:aws:sqs:us-east-2:211998422884:trinity-beast-queued-usage-logs |
sqs:GetQueueAttributes |
arn:aws:sqs:us-east-2:211998422884:trinity-beast-queued-usage-logs |
secretsmanager:GetSecretValue |
arn:aws:secretsmanager:us-east-2:211998422884:secret:trinity-beast-secrets* |
AWSLambdaBasicExecutionRole |
AWS managed policy (CloudWatch Logs) |