Skip to main content

SOC2 PI1.4 - Error Detection and Correction

Control: PI1.4 - Error Detection and Correction Status: Procedure template Last Updated: 2025-12-16 Owner: Infrastructure Administrator


Overview​

This document defines infrastructure-level error detection capabilities and application-level error handling requirements for CloudForge CI. These procedures are a template for addressing SOC2 PI1.4 (Error Detection and Correction) requirements.


Infrastructure Error Detection (Automated)​

CloudForge CI configures the following infrastructure monitoring:

CloudWatch Alarms​

Thresholds depend on the security profile (production / staging / dev):

Alarm TypeMetricThresholdCreated byAction
High CPUCPUUtilization70% / 80% / 90%, two 5-minute periodsSecurityMonitoringFactorySNS notification
High MemoryMemoryUtilization80% / 85% / 90%, two 5-minute periodsSecurityMonitoringFactorySNS notification
5xx ErrorsHTTPCode_ELB_5XX_Count5 / 7 / 10 per minuteAlarmFactorySNS notification
4xx ErrorsHTTPCode_ELB_4XX_Count20 / 30 / 50 per 5 minutes, two periodsAlarmFactorySNS notification
Target Response TimeTargetResponseTime2s / 3s / 5s, two 5-minute periodsAlarmFactorySNS notification

Unhealthy target detection relies on the load balancer health checks below.

Health Checks​

// AlbFactory configures health checks:
.healthCheck(HealthCheck.builder()
.path(healthCheckPath)
.healthyHttpCodes("200-299")
.interval(Duration.seconds(30))
.timeout(Duration.seconds(5))
.healthyThresholdCount(2)
.unhealthyThresholdCount(3)
.build())

Database Monitoring​

MetricThresholdIndicates
DatabaseConnections> 80% maxConnection pool exhaustion
FreeableMemory< 256MBMemory pressure
FreeStorageSpace< 10GBDisk space critical
ReadLatency/WriteLatency> 100msI/O bottleneck
ReplicaLag> 60sReplication issues

Container/ECS Monitoring​

MetricThresholdAction
Service Desired vs RunningMismatchDeployment issue
Task StoppedUnexpected stopContainer crash
CPU/Memory Reservation> 80%Scaling needed

Application Error Handling Requirements​

Applications deployed on CloudForge CI must implement:

1. Structured Error Logging​

Requirement: All errors must be logged in structured JSON format.

{
"timestamp": "2025-12-16T10:30:00Z",
"level": "ERROR",
"service": "payment-service",
"traceId": "abc123",
"error": {
"type": "ValidationError",
"message": "Invalid card number format",
"code": "CARD_001",
"stackTrace": "..."
},
"context": {
"userId": "user-123",
"requestId": "req-456"
}
}

Compliance: Enables CloudWatch Logs Insights queries for error analysis.

2. Error Classification​

Applications must classify errors:

CategoryHTTP StatusRetryAlert
Client Error4xxNoAggregate
Validation Error400NoNo
Authentication Error401/403NoThreshold
Server Error5xxYesImmediate
Dependency Error502/503/504YesImmediate
Timeout504YesImmediate

3. Error Response Format​

Standard error response structure:

{
"error": {
"code": "VALIDATION_ERROR",
"message": "Human-readable error message",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
],
"requestId": "req-456"
}
}

4. Retry Logic with Exponential Backoff​

For transient errors, implement retry:

// Example retry configuration
RetryConfig.builder()
.maxAttempts(3)
.waitDuration(Duration.ofMillis(500))
.retryOnResult(response -> response.getStatusCode() >= 500)
.retryOnException(e -> e instanceof TimeoutException)
.exponentialBackoffMultiplier(2)
.build();

5. Circuit Breaker Pattern​

Prevent cascade failures:

// Example circuit breaker
CircuitBreakerConfig.builder()
.failureRateThreshold(50)
.waitDurationInOpenState(Duration.ofSeconds(30))
.slidingWindowSize(10)
.build();

Error Correction Procedures​

Automated Correction​

Error TypeAutomated Response
Unhealthy containerECS replaces task
Failed health checkALB removes target
High CPUAuto Scaling adds capacity
Deployment failureCloudFormation rollback

Manual Correction​

Error TypeProcedure
Application bugHotfix → PR → Deploy
Data corruptionRestore from backup
Configuration errorUpdate deployment context, redeploy
Dependency failureImplement fallback, notify vendor

Incident Response​

Error Detected
↓
Automated alert (CloudWatch → SNS → Slack/Email)
↓
Acknowledge alert
↓
Triage: Auto-recoverable or manual intervention?
↓
[Auto-recoverable] [Manual intervention]
↓ ↓
Monitor recovery Investigate root cause
↓ ↓
Document Implement fix
↓
Test & deploy
↓
Document & post-mortem

Monitoring Dashboards​

Application Team Dashboard Requirements​

Each application should have a CloudWatch dashboard with:

  1. Error Rate Panel

    • 5xx errors per minute
    • 4xx errors per minute
    • Error rate percentage
  2. Latency Panel

    • P50, P90, P99 response times
    • Target response time trend
  3. Availability Panel

    • Healthy host count
    • Request count
    • Success rate
  4. Resource Panel

    • CPU utilization
    • Memory utilization
    • Connection count

Example Dashboard Definition​

{
"widgets": [
{
"type": "metric",
"properties": {
"title": "Error Rate",
"metrics": [
["AWS/ApplicationELB", "HTTPCode_Target_5XX_Count", "TargetGroup", "${tg}"],
[".", "HTTPCode_Target_4XX_Count", ".", "."]
],
"period": 60,
"stat": "Sum"
}
}
]
}

Error Reporting​

Daily Error Summary (Automated)​

CloudWatch Logs Insights query for daily error report:

fields @timestamp, @message
| filter @message like /ERROR/
| stats count(*) as errorCount by bin(1h)
| sort @timestamp desc

Weekly Error Review​

Agenda:

  1. Review top errors by frequency
  2. Identify recurring issues
  3. Prioritize fixes
  4. Update error handling if needed

Evidence: Weekly review notes stored in [INTERNAL]/engineering/error-reviews/


Validation and Data Integrity​

Input Validation Requirements​

// All user input must be validated
public class ValidationRules {
// Required fields
@NotNull
@NotEmpty
private String requiredField;

// Format validation
@Email
private String email;

// Range validation
@Min(0) @Max(100)
private Integer percentage;

// Pattern validation
@Pattern(regexp = "^[A-Z]{2}[0-9]{6}$")
private String referenceCode;
}

Output Validation​

Applications must validate:

  • Response data matches expected schema
  • Sensitive data is masked/excluded
  • Error responses don't leak internal details

Evidence Collection​

Automated Evidence​

  • CloudWatch alarm history
  • CloudWatch Logs (error logs)
  • X-Ray traces (if enabled)
  • ECS task stopped events
  • ALB access logs

Manual Evidence​

Evidence TypeLocationRetention
Error review meeting notesConfluence3 years
Incident post-mortemsConfluence7 years
Bug fix ticketsJira7 years
Dashboard screenshotsConfluence1 year

Compliance Mapping​

RequirementImplementationEvidence
SOC2 PI1.4Error logging, monitoring, correctionCloudWatch, incident tickets
SOC2 CC7.2System monitoringCloudWatch alarms
PCI-DSS Req 10.2Audit loggingCloudTrail, application logs
HIPAA §164.312(b)Audit controlsCloudWatch Logs

Responsibilities​

RoleResponsibility
Infrastructure AdministratorInfrastructure monitoring, alerting setup, error triage, incident response
Application DeveloperApplication error handling, logging, dashboards

Document Control

VersionDateAuthorChanges
1.02025-12-16CloudForge CIInitial release