Microservice Anomalous Request Triage: Distinguishing Unauthorized Access from Overreactive Responses
This article explains how to triage anomalous requests in microservices by first separating a failure chain from a security incident. It covers resource contention, API contract violations, overreactive server responses, and unauthorized access; shows how logs and distributed tracing support reconstruction; discusses evidence reliability and tamper resistance; and presents a tiered policy engine for observation, rate limiting, isolation, circuit breaking, and rollback. It also provides threshold-setting guidance, boundaries for isolation and circuit breaking, canary and rollback practices for false positives, and a list of items to verify.
Start with the Conclusion
When investigating an anomaly, first determine whether it is a failure chain or a security incident. Resource contention, API contract violations, and overreactive responses usually belong to a failure chain, and the goal is to keep the service available. Only when there is evidence of unauthorized access should the security blocking process be invoked. The strength of blocking actions must match the strength of evidence; when evidence is insufficient, observe first rather than isolate or circuit-break directly.
1. The Four Stages of the Investigation Chain Are Not Four Classifications
A core service under high concurrency encountered anomalous requests from one caller, then responses became slower, and monitoring eventually blocked the traffic. The event can be divided into four stages, but these four stages are an investigation order, not four security classifications.
1. Resource Contention: An Ordinary Concurrency Failure
When multiple requests compete for database row locks, distributed locks, or hot cache entries at the same time, wait times become longer. This is a normal concurrency scenario, and concurrency control mechanisms should ensure ordered access.
- Observability metrics: P95 and P99 lock wait times, connection pool wait queue length, and timeout rate.
- Threshold source: use the historical baseline for the same time period over the last 14 days and combine it with the business SLO. Do not look only at a single peak.
- Handling boundary: queuing or fast failure is normal handling and does not constitute a security incident.
2. API Contract Violation: Not Unauthorized Access
The caller sends requests that do not conform to the API contract, such as missing required fields, incorrect parameter types, or repeated calls that exceed the agreed frequency. These requests are usually caused by client defects or configuration errors and do not directly crash the service.
- Observability metrics: number of 4xx errors, request rate per caller, and quota hits.
- Handling boundary: return standard error codes, record the caller identity, and rate-limit callers that exceed quota. Generally, there is no need to circuit-break the entire service.
3. Overreactive Response: A Server-Side Fault-Tolerance Defect
After receiving an anomalous request, if the server does not handle it through standard fault-tolerance mechanisms, it may enter an overreactive state. There are three common causes:
- An uncaught exception is thrown directly upward, keeping the request thread occupied for a long time.
- Retries after failure are too aggressive and form a retry storm.
- Blocking calls have no timeout; the thread pool is exhausted, and subsequent requests all queue.
Thread pool exhaustion usually causes cascading failures. Infinite loops and memory overflows are more specific faults and cannot be concluded from a single anomaly. They require separate evidence: a hot stack that repeatedly appears in thread dumps, heap memory snapshots, and changes in collection frequency and duration in GC logs. Without this evidence, the conclusion should be written as “may exist” and include items to verify.
4. Unauthorized Access: A Security Issue Requiring Separate Evidence
Unauthorized access means a caller, after authentication, accesses a resource it is not authorized to access or performs an operation it is not authorized to perform. Determining unauthorized access requires the following evidence:
- Records of authorization failures or permission code mismatches.
- Resource ownership relationships, such as which tenant or user an order belongs to.
- The mapping between the caller principal and the requested operation.
Without such evidence, even if the request is rejected, it can only be classified as an API contract violation.
The typical failure chain is: resource contention causes timeouts, the caller retries, and the server produces an overreactive response. There is no unauthorized access in this chain, so it cannot go directly into security blocking.
2. Monitoring Retrospective: Log Audit and Distributed Tracing
Determining responsibility after the fact depends on two types of data: logs and call chains. Missing either type makes it difficult to reconstruct the scene.
1. Unified Log Structure
Access logs, error logs, and business logs from each node should be aggregated into a log service. Open-source options such as ELK and Loki can be used, as can cloud provider log services. Each log entry should contain the following unified fields:
{"traceId": "req-9f8a7b6c5d4e","spanId": "span-001","parentSpanId": "span-000","timestamp": "2026-11-24T10:30:45.123Z","service": "order-service","action": "lock_inventory","status": "ERROR","errorCode": "AUTH_SCOPE_MISMATCH","callerId": "checkout-service","tenantId": "tenant-0231","authSubject": "sub-7e21c9","permissionCode": "inventory:write","detail": "permission code does not cover target resource"}
Field descriptions:
- traceId: an identifier that runs through the entire call chain. It is generated by the entry service and passed through unchanged by downstream services.
- spanId and parentSpanId: identify a single call segment and its parent-child relationship, used to reconstruct the call tree.
- timestamp: use a unified UTC time. Node clocks must be synchronized via NTP or PTP; otherwise, cross-node time ordering will be distorted.
- callerId: the service identity of the caller, used to locate the request source.
- tenantId, authSubject, permissionCode: the fields actually needed to determine unauthorized access. Recording only the service name cannot identify the specific unauthorized principal.
- errorCode: use standard error codes; avoid recording only vague states such as “ERROR”.
Do not write passwords, tokens, or sensitive personal information into logs. authSubject should use a hash or pseudonymous ID; fields such as phone numbers and identity document numbers must be masked before storage.
2. Distributed Tracing Checklist
During implementation, confirm each of the following:
- traceId injection: both HTTP headers and message headers in message queues must carry traceId. If missing, it should be generated by the entry gateway.
- Span reporting: every remote call, database access, and cache access should produce a span.
- Sampling strategy: retain all error requests and slow requests; sample normal requests proportionally. Full retention must have a cost cap and be masked before storage.
- Cost estimation: log volume is approximately QPS × bytes per log entry × 86,400 seconds × retention days. For example, at 2,000 QPS and 800 bytes per entry, raw logs are about 135 GB per day. Set the storage budget based on this figure before compression.
- Retention period: set according to compliance requirements and investigation needs. Retain recent logs as hot data for fast queries, and move cold data to low-cost storage.
- Clock synchronization: monitor the clock offset of each node and alert when it exceeds the threshold.
- Query fields: support retrieval by at least traceId, service, callerId, errorCode, tenantId, and time range.
- Access auditing: record who queried which logs and when.
3. Scope of Scene Reconstruction and Evidence Reliability
Using the above method, the call chain can be reconstructed within the log retention period, showing when the caller initiated the request, when the server began to exhaust resources, and where the anomaly propagated upstream.
Evidence reliability depends on four conditions: completeness of collection, clock synchronization, whether logs can be tampered with, and controlled access.
To improve completeness and tamper resistance, the following measures can be taken:
- Hash chain: the hash value of each log batch includes the hash of the previous batch. If any intermediate batch is changed, subsequent verification will fail.
- Batch signing: sign each batch, and manage signing keys separately from log storage.
- Periodic verification: recompute the hash chain and compare signatures at fixed intervals, and write the verification results to the audit log.
- Write once read many (WORM) storage: restrict deletion and overwrite operations.
These measures significantly reduce tampering risk but cannot guarantee that logs are absolutely immutable. Someone with storage administrator privileges may still damage log integrity. Therefore, critical conclusions should be supported by at least two independent sources of evidence, such as gateway logs and server logs corroborating each other.
4. Security Policy Engine: Tiered Handling and Blocking Boundaries
The policy engine decides handling actions based on evidence. Conclusions should be written as technical descriptions such as “API contract violation,” “suspected unauthorized access,” or “unauthorized access,” with the supporting metrics and time period. These terms describe technical phenomena and do not constitute a legal or liability determination.
1. Tiered Handling Table
| Level | Triggering Evidence | Handling Action | Applicable Boundary | Review Requirement |
|---|---|---|---|---|
| L1 Observation | A single metric anomaly or a single timeout | Log and alert; traffic remains unchanged | Used when evidence is insufficient or false positives are likely | On-duty confirmation is sufficient |
| L2 Rate limiting | The caller exceeds quota and has an API contract violation record | Rate-limit by caller; return 429 or a standard error code | Only the individual caller; other callers are unaffected | On-duty confirmation is sufficient |
| L3 Isolation | Unauthorized access evidence is established (authorization failure plus permission code mismatch), and the impact scope is confirmed | Isolate traffic from that caller or related nodes | Only for confirmed unauthorized principals | On-duty lead and security lead jointly confirm |
| L4 Circuit breaking | Downstream error rate or slow-call ratio exceeds the threshold and persists across multiple windows | Circuit-break downstream calls; restore after half-open probing | Used to protect the service from being dragged down by downstream, not to punish callers | Service owner confirms circuit-breaking duration and recovery conditions |
| L5 Rollback | Metrics deteriorate after a change is deployed, or a false positive has been confirmed | Roll back the version or configuration | Rollback scope is limited to this change | Change owner and security review jointly approve |
2. Threshold Setting Method
Thresholds should be based on historical data, not filled in from experience. The steps are:
- Collect P99 latency, error rate, and timeout rate from the same time period over the last 14 days as the baseline.
- Use baseline plus k standard deviations as the initial threshold, with k usually set to 3. If the business has an explicit SLO, use the SLO as the upper limit.
- Require the anomaly to persist for three consecutive one-minute windows before triggering an action. Jitter in a single window does not trigger.
- First run in observation mode for one to two weeks and measure the false positive rate. If the false positive rate is high, raise the threshold or lengthen the window.
3. Applicable Boundaries of Circuit Breaking and Isolation
Circuit breaking is suitable for cascading failures caused by downstream instability. It is not suitable for the following situations:
- Upstream input errors. These should be handled by parameter validation; circuit-breaking the downstream does not help.
- Occasional errors from a single caller. These should be handled by rate limiting or retry policies.
- Scenarios without clear recovery conditions. Circuit breaking must set a maximum duration and half-open probing conditions.
Isolation can only target a confirmed unauthorized principal. An increase in the error rate alone is not enough to isolate a caller.
4. Rollback and Canary Handling for False Positives
A policy false positive means a normal request is incorrectly blocked. The handling approach is as follows:
- False positive determination: reviewers sample and check blocked requests. If the proportion of false-positive samples exceeds the agreed value, the policy automatically downgrades to observation mode.
- Canary release: new policies are ramped at 1%, 10%, 50%, and 100%. Observe each level for 30 minutes or for one full business cycle.
- Version management: policy configurations keep historical versions and support one-click rollback to the previous version.
- Rollback drills: write rollback steps into the runbook and drill regularly to ensure completion within minutes during an emergency.
During the canary period, compare the interception rate, error rate, and business success rate between the canary group and the control group. If the difference is significant, pause the ramp and investigate the cause.
5. Conclusions and Items to Verify
- Evidence reliability: depends on log integrity, clock synchronization, and access control. Hash chains and batch signatures improve trustworthiness but cannot absolutely prevent tampering.
- Handling boundaries: resource contention, API contract violations, and overreactive responses are handled as failures by default, with rate limiting, fast failure, and observation as the main actions. Only when unauthorized access evidence is established should isolation be used. Circuit breaking is only for protecting the service itself.
- Item to verify 1: whether this incident involved real unauthorized access. Check authorization failure records, permission codes, and resource ownership relationships.
- Item to verify 2: whether the overreactive response involved an infinite loop or memory overflow. Check thread dumps, heap memory snapshots, and GC logs.
- Item to verify 3: the current threshold’s false positive rate in this business. Complete the observation-mode statistics.
- Item to verify 4: whether the interception rate and business success rate after canary ramp meet expectations.
