gRPC & High Performance APIs · درس

تصميم خلفية دردشة آنية باستخدام gRPC

اطّلعوا على دراسة حالة واقعية: بناء بنية خلفية قابلة للتوسع لدردشة آنية باستخدام البث ثنائي الاتجاه في gRPC والتوزيع على عدة مستهلكين وتتبع الحضور.

الدرس 4 من 413 خطوة

تصميم خلفية دردشة آنية باستخدام gRPC درس مجاني في gRPC & High Performance APIs على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في gRPC & High Performance APIs، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة gRPC & High Performance APIs 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Case Study

We design a chat backend that must deliver messages instantly to thousands of connected users. gRPC bidirectional streaming is a natural fit for this long-lived, two-way flow.

Defining the Service

The core is a bidi stream: clients send messages and receive others' messages over the same call.

service Chat {
  rpc Connect(stream ClientEvent) returns (stream ServerEvent);
}

Per-Connection Sessions

Each open stream is a user session. The server tracks the stream handle so it can push messages to that specific user later.

The Fan-Out Problem

When one user posts to a room, the server must deliver it to every other member's stream. This fan-out is the heart of chat scaling.

In-Process Hub

A simple design keeps a hub mapping rooms to subscriber channels. Posting iterates members and sends to each.

func (h *Hub) Broadcast(room string, msg *ServerEvent) {
  for _, sub := range h.rooms[room] {
    sub.outbox <- msg
  }
}

Scaling Past One Instance

Users on different server instances must still see each other. Introduce a message bus (Redis Pub/Sub, NATS, Kafka) so instances relay messages to one another.

Cross-Instance Flow

An instance publishes new messages to the bus; every instance subscribes and forwards to its own local connections. This decouples delivery from where users connect.

Presence and Typing

Presence (online/offline) and typing indicators are just more event types on the stream. Track last-seen timestamps and broadcast presence changes via the same fan-out path.

Backpressure per Client

A slow client must not stall the hub. Give each session a bounded outbox; if it overflows, drop or disconnect that client instead of blocking everyone.

select {
case sub.outbox <- msg:
default:
  disconnect(sub) // slow consumer
}

Reconnection and Delivery

Networks drop. Clients reconnect and resume from a last-seen message id. Persist recent history so missed messages can be replayed on reconnect.

Operational Concerns

Production chat needs:

  • Keepalive to detect dead connections
  • Authentication on connect (token in metadata)
  • Metrics on active streams and fan-out latency
  • Graceful drain on deploy

Quick Check

Test your chat-design knowledge.

Recap

You designed a real-time chat backend:

  • Bidirectional streaming models each user session
  • A hub fans out room messages to subscribers
  • A message bus relays across multiple instances
  • Presence/typing are extra event types; per-client backpressure protects the hub
  • Reconnection replays missed messages; ops needs keepalive, auth, metrics, drain
البدء مجانًا

تعلم gRPC & High Performance APIs مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «تصميم خلفية دردشة آنية باستخدام gRPC» مجاني؟

نعم — نص درس «تصميم خلفية دردشة آنية باستخدام gRPC» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة gRPC & High Performance APIs، انتقل إلى CoddyKit PRO. تتضمن دورة gRPC & High Performance APIs 4 دروس في المجموع.

ماذا ستتعلم في «تصميم خلفية دردشة آنية باستخدام gRPC»؟

اطّلعوا على دراسة حالة واقعية: بناء بنية خلفية قابلة للتوسع لدردشة آنية باستخدام البث ثنائي الاتجاه في gRPC والتوزيع على عدة مستهلكين وتتبع الحضور. تتمرن على gRPC & High Performance APIs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ gRPC & High Performance APIs؟

لا تُشترط خبرة سابقة. gRPC & High Performance APIs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تصميم خلفية دردشة آنية باستخدام gRPC»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس gRPC & High Performance APIs هذا؟

نعم. كل درس في gRPC & High Performance APIs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. بناء بوابات عالية معدل النقل
  2. أنماط المرونة المتقدمة
  3. مستقبل واجهات برمجة التطبيقات عالية الأداء
  4. تصميم خلفية دردشة آنية باستخدام gRPC
← العودة إلى gRPC & High Performance APIs