0Pricing
System Design Basics for Backend Developers · Lekcja

Projektowanie systemu czatu czasu rzeczywistego

Prześledź projekt systemu aplikacji czatu czasu rzeczywistego, obejmujący połączenia, dostarczanie wiadomości, przechowywanie danych i skalowanie.

Projektowanie systemu czatu czasu rzeczywistego to bezpłatna lekcja System Design Basics for Backend Developers na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej System Design Basics for Backend Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs System Design Basics for Backend Developers zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

The Problem

Design a chat system like WhatsApp or Slack: users send messages that appear on recipients' devices instantly, with history, online presence, and delivery receipts — at the scale of millions of concurrent users.

Requirements

Clarify scope first:

  • Functional: 1:1 and group chat, message history, presence, delivery/read receipts
  • Non-functional: low latency, high availability, ordered delivery, horizontal scale

Why Not Plain HTTP?

Classic HTTP is request-response — the server cannot push. Polling wastes resources and adds latency. Real-time chat needs a persistent, bidirectional connection.

WebSockets

WebSockets upgrade an HTTP connection into a long-lived, full-duplex channel. The server can push a message the instant it arrives. This is the backbone of real-time chat.

GET /chat HTTP/1.1
Upgrade: websocket
Connection: Upgrade

# After upgrade: server can push frames anytime

Connection Servers

A fleet of connection servers holds the open WebSockets. Since a sender and recipient may be connected to different servers, you need a way to route a message from one server to another.

Routing Between Servers

A presence/session store (e.g. Redis) maps each user to the connection server holding their socket. A message broker or pub/sub forwards messages to the right server so it can push to the recipient.

user_to_server = {
  'alice': 'conn-3',
  'bob': 'conn-7'
}
# alice -> bob: route message to conn-7

Storing Messages

Chat is write-heavy with huge volume. A wide-column store like Cassandra suits it: partition by conversation id, cluster by timestamp, so fetching recent history in order is fast.

PRIMARY KEY ((conversation_id), message_ts)
WITH CLUSTERING ORDER BY (message_ts DESC)

Delivery Guarantees

Use a per-user inbox queue and acknowledgements. Mark messages sent, delivered, and read. If a recipient is offline, queue the message and deliver when they reconnect; retries plus message IDs keep it idempotent.

Ordering

Messages must appear in a consistent order. Attach a monotonic sequence or timestamp per conversation. Clients sort by it, so even out-of-order network delivery is corrected on display.

import time
base = int(time.time() * 1000)
seq = [base, base + 1, base + 2]
print('ordered message ids:', seq)

Group Chat at Scale

Group messages fan out to every member. For small groups, push directly; for large ones, write once to the conversation and let members pull, or fan out asynchronously via the broker to avoid a write storm.

Putting It Together

The full picture: clients hold WebSockets to connection servers, a presence store routes via pub/sub, messages persist in a wide-column store, and queues plus receipts handle offline delivery and ordering. Each piece scales horizontally.

Quick Check

Test your understanding of real-time chat design.

Recap

You designed a real-time chat system:

  • WebSockets give persistent bidirectional connections
  • A presence store plus pub/sub routes messages between connection servers
  • A wide-column store holds ordered history
  • Queues and receipts handle offline delivery; ordering uses per-conversation sequences

Często zadawane pytania

Czy lekcja „Projektowanie systemu czatu czasu rzeczywistego” jest bezpłatna?

Tak — pełny tekst „Projektowanie systemu czatu czasu rzeczywistego” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu System Design Basics for Backend Developers, przejdź na CoddyKit PRO. Kurs System Design Basics for Backend Developers zawiera 4 lekcji w sumie.

Co nauczysz się w „Projektowanie systemu czatu czasu rzeczywistego”?

Prześledź projekt systemu aplikacji czatu czasu rzeczywistego, obejmujący połączenia, dostarczanie wiadomości, przechowywanie danych i skalowanie. Ćwiczysz System Design Basics for Backend Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć System Design Basics for Backend Developers?

Nie wymagamy żadnego doświadczenia. System Design Basics for Backend Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Projektowanie systemu czatu czasu rzeczywistego”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji System Design Basics for Backend Developers?

Tak. Każda lekcja System Design Basics for Backend Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Projektowanie skracacza adresów URL
  2. Budowanie kanału mediów społecznościowych
  3. Skalowanie platformy e-commerce
  4. Projektowanie systemu czatu czasu rzeczywistego
← Powrót do System Design Basics for Backend Developers