Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Outbox Pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for transactional outbox, polling publisher, and reliable messaging audits.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
설치 방법 보기설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.
Quick reference for Transactional Outbox pattern and PHP implementation guidelines.
┌─────────────────────────────────────────────────────────────────────────┐
│ TRANSACTIONAL OUTBOX PATTERN │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────────────────┐ │
│ │ SINGLE TRANSACTION │ │
│ │ ┌──────────┐ ┌───────────────┐ ┌────────────────┐ │ │
│ │ │ Business │─────▶│ Domain Table │ │ Outbox Table │ │ │
│ │ │ Logic │ │ (orders) │ │ (outbox_msgs) │ │ │
│ │ └──────────┘ └───────────────┘ └────────────────┘ │ │
│ │ │ ▲ ▲ │ │
│ │ └───────────────────┴───────────────────────┘ │ │
│ │ COMMIT/ROLLBACK │ │
│ └──────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────┐ ┌──────────────────────────┐ │
│ │ Message Relay │───────────────────▶│ Message Broker │ │
│ │ (Polling/CDC) │ publish events │ (RabbitMQ/Kafka) │ │
│ └──────────────────┘ └──────────────────────────┘ │
│ │ │
│ ▼ │
│ Marks messages as processed │
│ │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Publishing Strategies: │
│ • Polling Publisher - Periodic poll for unprocessed messages │
│ • Transaction Log Tailing (CDC) - Debezium, Maxwell │
│ • Event Sourcing + Projections - Events = Outbox │
│ │
│ Guarantees: │
│ • At-least-once delivery │
│ • No message loss on service crash │
│ • Transactional consistency between data and events │
│ │
└─────────────────────────────────────────────────────────────────────────┘
| Concept | Description |
|---|---|
| Outbox Table | Database table storing pending messages within same transaction |
| Message Relay | Background process that publishes messages from outbox |
| Polling Publisher | Periodically queries outbox for unpublished messages |
| CDC (Change Data Capture) | Streams database changes to message broker |
| Idempotency Key | Unique identifier for message deduplication |
| At-least-once | Messages delivered at least once (consumers must be idempotent) |
<?php
declare(strict_types=1);
namespace Domain\Shared\Outbox;
final readonly class OutboxMessage
{
public function __construct(
public string $id,
public string $aggregateType,
public string $aggregateId,
public string $eventType,
public string $payload,
public \DateTimeImmutable $createdAt,
public ?string $correlationId = null,
public ?\DateTimeImmutable $processedAt = null,
public int $retryCount = 0
) {}
public function isProcessed(): bool
{
return $this->processedAt !== null;
}
public function withProcessed(\DateTimeImmutable $at): self
{
return new self(
$this->id,
$this->aggregateType,
$this->aggregateId,
$this->eventType,
$this->payload,
$this->createdAt,
$this->correlationId,
$at,
$this->retryCount
);
}
public function withRetry(): self
{
return new self(
$this->id,
$this->aggregateType,
$this->aggregateId,
$this->eventType,
$this->payload,
$this->createdAt,
$this->correlationId,
$this->processedAt,
$this->retryCount + 1
);
}
}
<?php
declare(strict_types=1);
namespace Domain\Shared\Outbox;
interface OutboxRepositoryInterface
{
public function save(OutboxMessage $message): void;
/** @param array<OutboxMessage> $messages */
public function saveAll(array $messages): void;
/** @return array<OutboxMessage> */
public function findUnprocessed(int $limit = 100): array;
public function markAsProcessed(string $id, \DateTimeImmutable $at): void;
public function incrementRetry(string $id): void;
public function delete(string $id): void;
}
<?php
declare(strict_types=1);
namespace Application\Shared\Outbox;
use Domain\Shared\Outbox\OutboxMessage;
use Domain\Shared\Outbox\OutboxRepositoryInterface;
final readonly class OutboxPublisher
{
public function __construct(
private OutboxRepositoryInterface $outbox,
private EventPublisherInterface $publisher,
private int $maxRetries = 3
) {}
public function processOutbox(int $batchSize = 100): int
{
$messages = $this->outbox->findUnprocessed($batchSize);
$processed = 0;
foreach ($messages as $message) {
try {
$this->publisher->publish(
$message->eventType,
$message->payload,
$message->correlationId
);
$this->outbox->markAsProcessed(
$message->id,
new \DateTimeImmutable()
);
$processed++;
} catch (\Throwable $e) {
$this->handleFailure($message, $e);
}
}
return $processed;
}
private function handleFailure(OutboxMessage $message, \Throwable $e): void
{
if ($message->retryCount >= $this->maxRetries) {
// Move to dead letter / log critical
$this->outbox->delete($message->id);
return;
}
$this->outbox->incrementRetry($message->id);
}
}
<?php
declare(strict_types=1);
namespace Application\Order\UseCase;
use Domain\Order\OrderRepositoryInterface;
use Domain\Shared\Outbox\OutboxRepositoryInterface;
use Domain\Shared\Outbox\OutboxMessage;
final readonly class PlaceOrderUseCase
{
public function __construct(
private OrderRepositoryInterface $orders,
private OutboxRepositoryInterface $outbox,
private TransactionInterface $transaction
) {}
public function execute(PlaceOrderCommand $command): OrderId
{
return $this->transaction->execute(function () use ($command): OrderId {
$order = Order::place(
OrderId::generate(),
CustomerId::fromString($command->customerId),
$command->items
);
$this->orders->save($order);
// Store event in outbox within same transaction
foreach ($order->releaseEvents() as $event) {
$this->outbox->save(new OutboxMessage(
id: $event->eventId,
aggregateType: 'Order',
aggregateId: $order->id()->toString(),
eventType: $event->eventName(),
payload: json_encode($event->toArray()),
createdAt: $event->occurredAt,
correlationId: $command->correlationId
));
}
return $order->id();
});
}
}
| Violation | Where to Look | Severity |
|---|---|---|
| Publish before commit | Event published without outbox | Critical |
| No idempotency key | OutboxMessage without unique ID | Critical |
| Two-phase commit | Distributed transaction attempt | Critical |
| Missing retry logic | No retry count in outbox | Warning |
| No dead letter handling | Failed messages lost | Warning |
| Unbounded polling | No limit on batch size | Warning |
| Synchronous publish in transaction | HTTP call in DB transaction | Critical |
# Find outbox implementations
Glob: **/Outbox/**/*.php
Glob: **/outbox*.php
Grep: "outbox|OutboxMessage|OutboxRepository" --glob "**/*.php"
# Check for proper transactional outbox
Grep: "->save.*->outbox|outbox.*transaction" --glob "**/UseCase/**/*.php"
# Detect anti-patterns: publishing in transaction
Grep: "transaction.*publish|->publish\(.*\)->commit" --glob "**/*.php"
# Find message relay/processor
Grep: "findUnprocessed|processOutbox|OutboxProcessor" --glob "**/*.php"
# Check for idempotency handling
Grep: "messageId|eventId|idempotencyKey" --glob "**/Consumer/**/*.php"
# Find Doctrine outbox table
Grep: "outbox_messages|OutboxMessage.*Entity" --glob "**/Infrastructure/**/*.php"
CREATE TABLE outbox_messages (
id UUID PRIMARY KEY,
aggregate_type VARCHAR(255) NOT NULL,
aggregate_id VARCHAR(255) NOT NULL,
event_type VARCHAR(255) NOT NULL,
payload JSONB NOT NULL,
correlation_id VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
processed_at TIMESTAMP NULL,
retry_count INT NOT NULL DEFAULT 0,
INDEX idx_unprocessed (processed_at, created_at)
);
For detailed information, load these reference files:
references/outbox-patterns.md — Implementation strategies and patternsreferences/antipatterns.md — Common violations with detection patternsreferences/php-specific.md — PHP 8.5 specific implementationsassets/report-template.md — Structured audit report template아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.
로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.
아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.
Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.
[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.
한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.