Code & Dev Compatible: claude

Transactional Outbox for Domain Events

Complexity Level: Expert
Prompt Code Block

Design a transactional outbox so we do not write to the database and then fail to publish the event, or publish the event and then roll back the write. CONTEXT Database: [POSTGRES] Publisher: [QUEUE NAME] Events: [LIST THE 3 EVENTS] Consumer requirement: at-least-once, handlers must be idempotent. DELIVER 1) The outbox table: id, aggregate type, aggregate id, type, payload jsonb, created_at, published_at. 2) The application transaction: business write and outbox insert commit together. Show the pseudocode. 3) The publisher loop: select unpublished for update skip locked, publish, mark published. What happens if publish succeeds and the mark fails (duplicate delivery) and why the consumer can stand it. 4) The consumer idempotency key (event id) and the table it uses. 5) Operational bits: lag metric, a poison event that fails forever, and how a human replays one event. 6) What this does not solve: ordering across aggregates. Say that. Do not dual-write to the queue inside the request without the outbox.

🌟 Example Output / Preview

### Generated Component Preview: ```typescript // Fully validated modern structure import { z } from 'zod'; export const RequestSchema = z.object({ id: z.string().uuid(), createdAt: z.date().default(() => new Date()), data: z.record(z.string(), z.any()) }); export type ValidatedRequest = z.infer<typeof RequestSchema>; ```

Prompt Metadata

DifficultyExpert
Compatibilityclaude

Primary Use Cases:

  • •Legacy code modernization & technical refactoring
  • •Full-stack layout generation & component structuring
  • •CI/CD workflow automation & unit/E2E testing suites

Associated Tags:

#outbox #postgres #events #typescript

💡 Pro Tips & Advice

1. Use bracketed items: Be sure to fill out all [PLACEHOLDER] elements with specific details before sending the prompt to the AI model.

2. Adjust temperature: For creative tasks, set AI temperature higher (e.g., 0.8), or lower (e.g., 0.2) for strict coding/technical tasks.

🔗 Related AI Prompts

Code & Dev
★ Featured

Full SaaS Landing Page Build Spec (SEO + Conversion)

You are a Staff Product Designer + Frontend Engineer + SEO strategist. Build a complete, production-ready marketing landing page f...

Compatible:claudeDiff:Advanced
#landing-page #saas #seo #nextjs #tailwind
Code & Dev
★ Featured 🔥 Trending

SaaS Analytics Dashboard Full Build Spec

You are a Principal Product Designer + Frontend Lead. Design and specify a complete [LIGHT | DARK] analytics dashboard for [PRODUC...

Compatible:claudeDiff:Intermediate
#dashboard #saas #ui #tailwind #seo
Code & Dev

SaaS Admin Panel Dashboard Build Spec

Design a full internal Admin Dashboard for [PRODUCT_NAME] used by [ADMIN_ROLE: support | ops | super-admin]. --- 🎯 CONTEXT Adm...

Compatible:claudeDiff:Intermediate
#admin #dashboard #saas #crud #tailwind