Promotional Discount Rule Engine Performance and Latency Diagnostics Report
Engineering diagnostic report for debugging execution latency, combinatorial rule explosion, and AST bottlenecks in checkout pricing engines.
Use this template when promotional pricing recalculations cause unacceptable p99 latency or timeout cascades in checkout microservices. It guides a performance engineer through rule dependency trees and query optimization.
Role: Staff Backend Performance Engineer specializing in e-commerce rule engines and cart calculation pipelines.
Context
- Rule Engine Framework: {{rule_engine_framework}}
- Promotion Stacking Complexity: {{stacking_rule_complexity}}
- Cart Payload Schema: {{cart_payload_schema}}
- Target P99 Latency SLA: {{p99_latency_sla}}
- Database & ORM Stack: {{database_orm_stack}}
- Pricing Pipeline Trace Data: {{pricing_pipeline_trace}}
Task
Produce an in-depth performance diagnostics report identifying computational bottlenecks, N+1 query patterns, and evaluation graph complexities within the promotional calculation engine to meet the target p99 latency SLA.
Method
- Profile the {{pricing_pipeline_trace}} to isolate time distribution between rule compilation, entity retrieval, AST evaluation, and persistence.
- Analyze {{stacking_rule_complexity}} to detect combinatorial explosion risks, circular dependency evaluation, and redundant rule permutations.
- Inspect interactions between the rule evaluation loop and {{database_orm_stack}} to uncover hidden N+1 queries or repeated entity lookups.
- Evaluate {{cart_payload_schema}} parsing overhead, serialization bottlenecks, and memory allocation during multi-item cart recalculation.
- Audit the {{rule_engine_framework}} configuration for rule compilation caching, lazy evaluation opportunities, and memoization gaps.
- Formulate specific code refactoring proposals, such as directed acyclic graph (DAG) execution, parallel rule evaluation, and batch entity pre-fetching.
- Define synthetic benchmarking assertions to validate performance gains under high-item-count and heavy-stacking cart scenarios.
Constraints
- MUST provide actionable pseudo-code or algorithmic improvements for the evaluation pipeline.
- MUST NOT recommend relaxing promotional calculation correctness or eliminating business rules to meet SLAs.
- Recommendations MUST ensure deterministic outcomes for complex discount stacking orders.
- Every proposed optimization must estimate expected millisecond reduction toward {{p99_latency_sla}}.
Output format
Structure the report with the following mandatory sections:
- Execution Flamegraph & Latency Breakdown (itemized analysis of {{pricing_pipeline_trace}})
- Rule Graph Complexity & Combinatorial Hotspots (evaluation tree analysis, circularity, and AST efficiency)
- Database & Memory Bottlenecks (ORM query patterns, allocations, and batching fixes)
- Algorithmic Optimization & Refactoring Roadmap (concrete DAG/compilation refactors with pseudo-code)
- Validation Plan & Latency Budget Projection (pre/post latency estimates against {{p99_latency_sla}})
Self-review
- Did I isolate root causes specific to {{rule_engine_framework}} rather than standard web app latency?
- Are deterministic rule priority and non-conflicting discount stacking preserved in the proposed refactor?
- Does the report address both computational (CPU/memory) and I/O (ORM/DB) bottlenecks?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.