Low-Latency Generative Ad Copy Engine Architecture Specification
Architect a high-performance backend service that serves dynamic marketing copy with strict caching, fallbacks, and latency SLOs.
Use this template when building backend infrastructure that powers programmatic copywriting and real-time ad variation generation. It produces a detailed technical specification for request routing, multi-tiered prompt caching, token budgets, and provider failover.
Role: Staff Backend Engineer specializing in High-Throughput Content Delivery and LLM Orchestration Infrastructure.
Context
- Latency Budget (P99): {{p99_latency_budget}}
- LLM Upstream Providers & Fallbacks: {{llm_provider_fallbacks}}
- Tiered Cache TTL & Invalidation Policy: {{cache_ttl_policy}}
- Dynamic Prompt Assembly Engine: {{prompt_assembly_rules}}
- Content Safety & Brand Guardrails: {{content_safety_filters}}
- Tenant Rate Limits: {{rate_limit_policy}}
Task
Draft an advanced backend engineering specification for an automated ad-copy generation API that satisfies strict enterprise latency budgets, implements semantic and exact-match caching, and guarantees graceful degradation under upstream LLM provider outages.
Method
- Translate {{p99_latency_budget}} into discrete latency allocations across network transit, auth, cache lookup, LLM inference, and validation.
- Design the dual-layer caching subsystem (L1 in-memory exact match, L2 vector-based semantic similarity) governed by {{cache_ttl_policy}}.
- Specify the runtime prompt construction pipeline that merges customer variables into {{prompt_assembly_rules}} without introducing injection vulnerabilities.
- Map out the upstream orchestration layer detailing connection pooling, active health checks, and fallback mechanisms across {{llm_provider_fallbacks}}.
- Design the streaming response middleware incorporating inline {{content_safety_filters}} before tokens reach the calling marketing frontend.
- Detail tenant throttling, token quota enforcement, and tier prioritization according to {{rate_limit_policy}}.
- Formulate a degradation matrix defining fallback behavior (e.g., pre-generated static templates) when upstream providers breach error budgets.
Constraints
- MUST NOT allow unvalidated or unsanitized prompt interpolations to reach upstream model gateways.
- MUST implement an automated circuit breaker that routes traffic to secondary providers within 200ms of primary failure.
- P99 cache hits MUST be served in under 15ms.
- Include exact OpenAPI 3.1 path definitions and error payload schemas.
Output format
-
- System Topology & Latency Budget Allocation (Table format, 200 words)
-
- Dual-Layer Caching & Eviction Specification (300 words)
-
- Dynamic Prompt Assembly & Guardrail Middleware Flow (250 words)
-
- Provider Failover, Circuit Breaking & Fallback Matrix (300 words)
-
- OpenAPI 3.1 Schema & Error Handling Contracts (YAML or JSON snippet)
Self-review
- Is every stage of the request pipeline accounted for within the specified P99 latency budget?
- Does the failover logic handle context window differences between primary and secondary LLM providers?
- Are safety filter latencies decoupled or parallelized with stream generation where appropriate?
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.