0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · 강의

이벤트 기반 아키텍처

Redis Pub/Sub이 이벤트 기반 마이크로서비스의 통신과 알림을 지원하는 방식을 살펴봅니다.

이벤트 기반 아키텍처은(는) CoddyKit의 무료 Redis Caching & Messaging (Pub/Sub, Streams) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Redis Caching & Messaging (Pub/Sub, Streams) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What is Event-Driven Architecture?

Welcome! In this lesson, we'll explore Event-Driven Architecture (EDA) and how Redis Pub/Sub is perfect for it.

EDA is a software design pattern where components communicate by reacting to changes in state, known as events.

  • Think of it like a news channel: producers publish news (events), and anyone interested (consumers) can tune in.

Key Concepts of EDA

EDA revolves around three main components:

  • Events: A record of something that happened (e.g., 'user registered', 'order placed'). They are immutable facts.
  • Event Producers: Services that detect an event and publish it to an event channel.
  • Event Consumers: Services that subscribe to event channels and react to specific events.

These components communicate indirectly.

Why Use EDA?

EDA offers significant benefits, especially for complex systems:

  • Loose Coupling: Producers don't need to know about consumers, making services independent.
  • Scalability: You can easily add new consumers without changing producers.
  • Real-time Responsiveness: Events are processed as they occur, enabling immediate reactions.
  • Flexibility: New features can be added by simply creating new consumers.

Redis Pub/Sub as the Event Bus

Redis Pub/Sub acts as an ideal event bus for EDA.

  • An event bus is the central communication channel for events.
  • In Redis, channels serve as these event buses.

Producers publish events to a Redis channel, and all interested consumers subscribed to that channel receive the event.

Decoupling Microservices

One of the biggest advantages of EDA with Redis Pub/Sub is decoupling microservices.

Imagine a user registration service. Without EDA, it might directly call an email service, a logging service, etc.

With EDA, the registration service just publishes a 'user registered' event. Email and logging services subscribe and react independently. This makes services easier to build and maintain!

Example: User Registration Event

Let's consider a practical scenario: a user registers on your application.

The User Service (producer) registers the user and then publishes a user:registered event to a Redis channel.

Other services, like a Notification Service or a Analytics Service (consumers), can then subscribe to this channel and perform their tasks.

Producer: Publishing an Event

Here's how a Python service might publish a user:registered event after a new user signs up. Make sure Redis is running!

import redis
import json
import time

r = redis.Redis(decode_responses=True)

def register_user(u_id, name, mail):
    print(f"User {name} registering...")
    event_data = {
        "user_id": u_id,
        "username": name,
        "email": mail,
        "timestamp": time.time()
    }
    r.publish("user_events", json.dumps(event_data))
    print(f"Published 'user:registered' for {name}")

if __name__ == "__main__":
    register_user("101", "alice", "alice@example.com")
    time.sleep(0.5)
    register_user("102", "bob", "bob@example.com")

Consumer: Reacting to an Event

Now, let's see how a Notification Service (consumer) could subscribe to the user_events channel and send a welcome email.

Run this code in a separate terminal after starting the producer.

import redis
import json
import time

r = redis.Redis(decode_responses=True)
p = r.pubsub()

def send_welcome_email(user_data):
    print(f"Sending email to {user_data['email']}")
    time.sleep(0.3) # Simulate sending
    print(f"Email sent to {user_data['username']}.")

if __name__ == "__main__":
    print("Notification Service started.")
    print("Subscribing to 'user_events'...")
    p.subscribe('user_events')
    for msg in p.listen():
        if msg['type'] == 'message':
            try:
                data = json.loads(msg['data'])
                print(f"Received: {data['username']}")
                send_welcome_email(data)
            except json.JSONDecodeError:
                print(f"Error decoding: {msg['data']}")
        time.sleep(0.01)

Notifications & Real-time Updates

Beyond microservice communication, Redis Pub/Sub in an EDA is excellent for real-time notifications.

  • Chat applications: Send new messages instantly to all participants.
  • Live dashboards: Update metrics or status for users in real time.
  • Alerts: Notify administrators of critical system events.

The immediate nature of Pub/Sub makes these scenarios simple to implement.

Quick Check: EDA with Redis

Which of the following best describes the role of Redis Pub/Sub in an Event-Driven Architecture?

Recap: EDA & Redis Pub/Sub

You've learned how Redis Pub/Sub is a powerful tool for building Event-Driven Architectures!

  • EDA relies on events, producers, and consumers for communication.
  • Redis Pub/Sub acts as an efficient event bus.
  • It enables loose coupling and scalability for microservices.
  • It's perfect for real-time notifications and inter-service communication.

This pattern makes your applications more resilient and flexible. Well done!

자주 묻는 질문

“이벤트 기반 아키텍처” 강의는 무료인가요?

네 — “이벤트 기반 아키텍처” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Redis Caching & Messaging (Pub/Sub, Streams) 강의 전체를 잠금 해제할 수 있습니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.

“이벤트 기반 아키텍처”에서 뭘 배우나요?

Redis Pub/Sub이 이벤트 기반 마이크로서비스의 통신과 알림을 지원하는 방식을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Redis Caching & Messaging (Pub/Sub, Streams)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Redis Caching & Messaging (Pub/Sub, Streams)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Redis Caching & Messaging (Pub/Sub, Streams)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“이벤트 기반 아키텍처” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Redis Caching & Messaging (Pub/Sub, Streams) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 패턴 일치 구독
  2. 실시간 채팅 설계
  3. 이벤트 기반 아키텍처
  4. 접속 상태 및 온라인 상태 추적
← Redis Caching & Messaging (Pub/Sub, Streams)(으)로 돌아가기