9148c358d0
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
209 lines
6.5 KiB
Markdown
209 lines
6.5 KiB
Markdown
---
|
|
id: wiki-2026-0508-queue-management-systems
|
|
title: Queue Management Systems
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [Message Queues, Job Queues, Task Queues]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.95
|
|
verification_status: applied
|
|
tags: [queue, messaging, async, distributed-systems]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: python
|
|
framework: rabbitmq-sqs-celery
|
|
---
|
|
|
|
# Queue Management Systems
|
|
|
|
## 매 한 줄
|
|
> **"매 producer 와 consumer 매 decouple — 매 buffered, durable, retried"**. RabbitMQ / SQS / Redis / Celery / Sidekiq / Temporal — 매 async work 매 backbone. 매 2026 매 Temporal-style durable execution 매 mainstream.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 queue types
|
|
- **FIFO point-to-point**: 매 single consumer per message (SQS, RabbitMQ direct).
|
|
- **Pub-sub fanout**: 매 N consumers 모두 받음 (SNS, Redis pub/sub, RabbitMQ fanout).
|
|
- **Priority**: 매 weighted consumption (RabbitMQ priority, Redis sorted set).
|
|
- **Delayed**: 매 ETA-based (SQS DelaySeconds, Sidekiq scheduled).
|
|
- **Dead letter**: 매 failed messages → DLQ.
|
|
|
|
### 매 delivery guarantees
|
|
- **At-most-once**: ack-on-delivery (Redis pub/sub).
|
|
- **At-least-once**: ack-on-process — 매 default for most prod queues.
|
|
- **Exactly-once**: 매 idempotent consumer + dedup (FIFO SQS, Kafka EOS).
|
|
|
|
### 매 patterns
|
|
- **Work queue**: 매 N workers, load-balanced.
|
|
- **Competing consumers**: 매 same.
|
|
- **Saga / orchestration**: 매 multi-step workflow (Temporal, Cadence).
|
|
- **Outbox**: 매 transactional message dispatch.
|
|
|
|
### 매 응용
|
|
1. Background jobs (email, image resize, PDF gen).
|
|
2. Microservice integration (order → fulfillment).
|
|
3. Rate limiting / throttling (queue as buffer).
|
|
4. Workflow orchestration (Temporal).
|
|
5. Batch processing (SQS → Lambda fanout).
|
|
|
|
## 💻 패턴
|
|
|
|
### Celery (Python)
|
|
```python
|
|
from celery import Celery
|
|
app = Celery("tasks", broker="redis://localhost:6379/0")
|
|
|
|
@app.task(bind=True, max_retries=3, retry_backoff=True)
|
|
def send_email(self, to: str):
|
|
try:
|
|
smtp.send(to)
|
|
except SMTPException as e:
|
|
raise self.retry(exc=e, countdown=2 ** self.request.retries)
|
|
|
|
# Producer
|
|
send_email.delay("alice@example.com")
|
|
```
|
|
|
|
### RabbitMQ work queue
|
|
```python
|
|
import pika
|
|
conn = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
|
|
ch = conn.channel()
|
|
ch.queue_declare(queue="tasks", durable=True)
|
|
|
|
# Publisher
|
|
ch.basic_publish(
|
|
exchange="", routing_key="tasks", body=b"work",
|
|
properties=pika.BasicProperties(delivery_mode=2), # persistent
|
|
)
|
|
|
|
# Worker
|
|
ch.basic_qos(prefetch_count=1)
|
|
def callback(ch, method, props, body):
|
|
process(body)
|
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
ch.basic_consume(queue="tasks", on_message_callback=callback)
|
|
ch.start_consuming()
|
|
```
|
|
|
|
### AWS SQS (boto3)
|
|
```python
|
|
import boto3
|
|
sqs = boto3.client("sqs")
|
|
url = sqs.get_queue_url(QueueName="jobs")["QueueUrl"]
|
|
|
|
# Send
|
|
sqs.send_message(QueueUrl=url, MessageBody=json.dumps(payload),
|
|
MessageGroupId="orders", MessageDeduplicationId=order_id) # FIFO
|
|
|
|
# Receive (long poll)
|
|
resp = sqs.receive_message(QueueUrl=url, WaitTimeSeconds=20, MaxNumberOfMessages=10)
|
|
for msg in resp.get("Messages", []):
|
|
process(json.loads(msg["Body"]))
|
|
sqs.delete_message(QueueUrl=url, ReceiptHandle=msg["ReceiptHandle"])
|
|
```
|
|
|
|
### Redis Streams (consumer groups)
|
|
```python
|
|
import redis
|
|
r = redis.Redis()
|
|
r.xgroup_create("orders", "fulfillment", id="0", mkstream=True)
|
|
|
|
# Producer
|
|
r.xadd("orders", {"id": "42", "total": "99"})
|
|
|
|
# Consumer
|
|
while True:
|
|
msgs = r.xreadgroup("fulfillment", "worker-1", {"orders": ">"}, count=10, block=5000)
|
|
for stream, entries in msgs or []:
|
|
for mid, data in entries:
|
|
process(data)
|
|
r.xack("orders", "fulfillment", mid)
|
|
```
|
|
|
|
### Temporal workflow (durable execution)
|
|
```python
|
|
from temporalio import workflow, activity
|
|
from datetime import timedelta
|
|
|
|
@activity.defn
|
|
async def charge(card: str, amount: int) -> str:
|
|
return payment_api.charge(card, amount)
|
|
|
|
@workflow.defn
|
|
class OrderWorkflow:
|
|
@workflow.run
|
|
async def run(self, order: dict) -> str:
|
|
tx = await workflow.execute_activity(
|
|
charge, order["card"], order["total"],
|
|
start_to_close_timeout=timedelta(seconds=30),
|
|
retry_policy=RetryPolicy(maximum_attempts=5),
|
|
)
|
|
await workflow.execute_activity(ship, order, ...)
|
|
return tx
|
|
```
|
|
|
|
### Outbox pattern (transactional)
|
|
```python
|
|
def place_order(db, order):
|
|
with db.transaction():
|
|
db.execute("INSERT INTO orders ...", order)
|
|
db.execute("INSERT INTO outbox (topic, payload) VALUES (?, ?)",
|
|
"orders.created", json.dumps(order))
|
|
# separate poller relays outbox → broker (at-least-once)
|
|
```
|
|
|
|
### Dead letter queue handling
|
|
```python
|
|
# RabbitMQ DLX
|
|
ch.queue_declare("tasks", arguments={
|
|
"x-dead-letter-exchange": "dlx",
|
|
"x-message-ttl": 60000,
|
|
"x-max-retries": 3,
|
|
})
|
|
# DLQ consumer logs / alerts / manual replay
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Choice |
|
|
|---|---|
|
|
| 매 simple background jobs | Celery / Sidekiq / BullMQ |
|
|
| 매 enterprise messaging | RabbitMQ |
|
|
| 매 cloud-managed | SQS / Cloud Tasks |
|
|
| 매 ordered + dedup | FIFO SQS |
|
|
| 매 multi-step workflow | Temporal / Cadence / AWS Step Functions |
|
|
| 매 high throughput log | Kafka (technically not a queue) |
|
|
| 매 in-process | asyncio.Queue / channels |
|
|
|
|
**기본값**: 매 2026 매 durable workflow → Temporal. 매 simple jobs → BullMQ / Celery.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Async Programming]]
|
|
- 변형: [[Dead Letter Queue]]
|
|
- Adjacent: [[RabbitMQ]] · [[SQS]] · [[Temporal]] · [[Sidekiq]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 retry policy design, 매 DLQ analysis (cluster failure modes), 매 workflow code scaffold.
|
|
**언제 X**: 매 throughput sizing — load test 직접.
|
|
|
|
## ❌ 안티패턴
|
|
- **No idempotency**: 매 at-least-once + non-idempotent → duplicate side effects. 매 dedup key 필수.
|
|
- **Infinite retry**: 매 poison message 매 forever — max attempts + DLQ.
|
|
- **Unbounded queue**: 매 producer faster than consumer — OOM. 매 backpressure / drop oldest.
|
|
- **Sync wait for queue result**: 매 anti-async — 매 callback / webhook / polling.
|
|
- **Long-running task in queue with short visibility timeout**: 매 redelivered while still running — race.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (RabbitMQ docs; AWS SQS docs; Temporal docs 1.20+).
|
|
- 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — full queue systems entry with Temporal |
|