Redis ile Yayınla/Abone Ol Arka Düzlemi
Bir Redis yayınla/abone ol arka düzlemi kullanarak birden çok WebSocket sunucu örneğini bağlayın; böylece iletiler, istemcilerin hangi düğüme bağlandığından bağımsız olarak onlara ulaşsın.
Redis ile Yayınla/Abone Ol Arka Düzlemi, CoddyKit'te ücretsiz bir WebSockets & Realtime Systems Programming dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, WebSockets & Realtime Systems Programming öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. WebSockets & Realtime Systems Programming kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
The Multi-Instance Problem
When you scale horizontally, clients connect to different server instances. A message published on node A will not reach a client connected to node B unless the nodes share it.
What a Backplane Does
A backplane is a shared channel every instance subscribes to. When one node receives a message, it publishes to the backplane, and all nodes deliver it to their local clients.
Why Redis Pub/Sub
Redis pub/sub is fast, simple, and widely available. Publishers send to a channel; all subscribers receive it instantly, making it a natural backplane.
Two Redis Connections
Redis requires separate clients for publishing and subscribing, because a subscribed connection cannot run normal commands.
const pub = redis.createClient();
const sub = redis.createClient();
await pub.connect();
await sub.connect();Subscribing on Startup
Each instance subscribes to the shared channel when it boots.
await sub.subscribe('ws-broadcast', (message) => {
deliverLocally(JSON.parse(message));
});Publishing Across Nodes
Instead of broadcasting only to local sockets, publish to Redis so every node hears it.
function broadcast(payload) {
pub.publish('ws-broadcast', JSON.stringify(payload));
}Delivering Locally
The subscribe callback fans the message out to the clients connected to that specific instance.
function deliverLocally(payload) {
for (const client of localClients) {
if (client.readyState === 1) client.send(JSON.stringify(payload));
}
}Avoiding Echo Loops
Since the publishing node also receives its own message via subscribe, deliver only through the backplane path so each message is sent once, not twice.
Scoping by Room
For room-based apps, include the room in the payload and let each node deliver only to its local members of that room, keeping the backplane channel count small.
pub.publish('ws-broadcast', JSON.stringify({ room: 'chat-1', data }));Limits of Redis Pub/Sub
Redis pub/sub is fire-and-forget: offline subscribers miss messages, and there is no persistence. For durability or replay, consider Redis Streams or a dedicated broker.
Best Practices
Run a healthy backplane:
- Use separate pub and sub clients
- Route all broadcasts through the backplane
- Scope messages by room to reduce work
- Know that pub/sub does not persist messages
Quick Check
Test your backplane knowledge.
Recap
You wired up a Redis pub/sub backplane:
- Use separate publish and subscribe clients
- Publish broadcasts to a shared channel
- Each node delivers to its local clients
- Scope by room and accept fire-and-forget limits
Your WebSocket app now scales across many instances.
Sıkça Sorulan Sorular
“Redis ile Yayınla/Abone Ol Arka Düzlemi” dersi ücretsiz mi?
Evet — “Redis ile Yayınla/Abone Ol Arka Düzlemi” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve WebSockets & Realtime Systems Programming kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. WebSockets & Realtime Systems Programming kursu toplamda 4 dersten oluşur.
“Redis ile Yayınla/Abone Ol Arka Düzlemi” dersinde ne öğreneceğim?
Bir Redis yayınla/abone ol arka düzlemi kullanarak birden çok WebSocket sunucu örneğini bağlayın; böylece iletiler, istemcilerin hangi düğüme bağlandığından bağımsız olarak onlara ulaşsın. WebSockets & Realtime Systems Programming ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
WebSockets & Realtime Systems Programming öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te WebSockets & Realtime Systems Programming, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.
“Redis ile Yayınla/Abone Ol Arka Düzlemi” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu WebSockets & Realtime Systems Programming dersinde kod yazıp çalıştırabilir miyim?
Evet. Her WebSockets & Realtime Systems Programming dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Yatay Ölçeklendirme Stratejileri
- WebSockets için Yük Dengeleme
- Dağıtık Durum Yönetimi
- Redis ile Yayınla/Abone Ol Arka Düzlemi