We may earn an affiliate commission when you visit our partners.
Course image
Hussein Nasser

However, what’s truly more challenging is designing real-time backend applications that support unfettered and ad-hoc bidirectional communication. The workloads of gaming, chatting, and even mission-critical real-time applications are unique in that they require a “push” nature to function effectively.

I spent a few months designing this course, and I chose the WebSockets protocol as the foundation for this work. WebSockets is by far the most widely available bidirectional protocol, supported across all clients—from browsers and command-line apps to runtimes like Node and Bun, and even other languages like C and Go.

Read more

However, what’s truly more challenging is designing real-time backend applications that support unfettered and ad-hoc bidirectional communication. The workloads of gaming, chatting, and even mission-critical real-time applications are unique in that they require a “push” nature to function effectively.

I spent a few months designing this course, and I chose the WebSockets protocol as the foundation for this work. WebSockets is by far the most widely available bidirectional protocol, supported across all clients—from browsers and command-line apps to runtimes like Node and Bun, and even other languages like C and Go.

While there is the newer WebTransport protocol, it isn’t yet as widely supported or battle-tested as WebSockets. Perhaps I’ll refresh this course in a few years when WebTransport matures.

This course is divided into three main sections:

1. WebSockets Internals – A deep dive into the inner workings of the protocol: the handshake, keepalive mechanisms, frame headers, and how it behaves over TLS. We’ll also discuss limitations—because I believe understanding limitations helps us build better applications. Each lecture will include a coding session and a quiz at the end of the section.

2. Scaling WebSockets – Taking your WebSocket knowledge to the maximum: how to scale this protocol over HTTP/1.1, HTTP/2, and HTTP/3. We’ll cover implementation with proxies in both stream mode (Layer 4) and application mode (Layer 7), along with their pros and cons. Each lecture will include a coding session and a quiz at the end of the section.

3. Building Real-Time System Designs – Putting everything into practice by designing two systems: an I/O-intensive chat system and a CPU-intensive game. I’ll propose multiple designs for each and choose one to implement.

Prerequisite: Fundamentals of Backend Engineering.

I hope you enjoy the course.

Enroll now

What's inside

Learning objectives

  • System design for real-time backend scaling
  • The internals of websockets
  • How websockets work
  • Websockets on secure tls
  • Scaling websockets with layer 4 proxying
  • Scaling websockets with layer 7 proxying
  • Websockets on http/2 and http/3
  • Building a real-time group chatting app (io intensive)
  • Building a real-time game app (cpu intensive)

Syllabus

Introduction
Welcome

Backend Engineers who are interested in leveling up their skills for real-time applications.

Course Outline
Read more

You can find the slides, referenced papers and source code under the resources of this lecture

If you can answer at least 8 out of 10 questions of this quiz move to next section

If we know the limitations of a protocol we can use it effectively.

This is an IO intensive , so we don't need as many backends so backends can be built in a mesh architecture.

No load balancing, client picks the server, only rooms within the server can be used.  No database, very simple.

Pros, simple

Cons, can't chat with other servers, no load balancing (one server can get overloaded if the url is shared)

Load balanced at stream level, client connects to the closest gateway, fleet of backends per gateway. a pub/sub to relay messages.

Client sends a message streamed through gateway streamed through a backend, a backend writes it to the pub/sub and all backends subscribe to the pub/sub, message pushed to all backends subscribed. queue room number.

Pros: Can chat with other all rooms, load is balanced

Cons: Complex, more components, resource intensive (streaming)

WS application load balancing, h2 web sockets or even shared web sockets (less connections more streams) , gateways. Still pub/sub

Pros: Better resource usage (compare to Design 2) , load balancing

Cons: Complex more components, Backend implementation is tricky (h2)

Because we don't anticipate lots of backends. We can drop the pub/sub and have the backends talk to each other directly.

WS application load balancing, h2 web sockets or even shared web sockets (less connections more streams) , gateways. 

Pros: Better resource usage (compare to Design 2) , load balancing

Cons: Less complex than Design 3, ditched the pub/sub system

  • Gamers join an interactive World game

  • Gamers interact with objects to “break”

  • Breaking an item gets XP based on the item

  • Only one gamer gets the XP (last one that destroy it)

  • All game World must update in real-time

CPU intensive, game need to scale

When a player make a move or attack, a ws msg is sent, the new game state is calculted and the diff is sent to  all players get the new state. Or we can send the moves and have the clients calculate the state.

No load balancing, locality and lowest latency. Clients pick the server. You can only join games in the same server you connect to. Simple design. We can restrict the number of players per game and restrict players accordingly (each box can handle x concurrent games)

When a player make a move or attack, a ws msg is sent, the new game state is calculated and the diff is sent to  all players get the new state. Or we can send the moves and have the clients calculate the state. The moves are labeled and ordered by arrival time.

No need for a database

Pros: Low latency

Cons: A single Server can be overloaded if too many players join

Load balancer that is game aware when a game is created it will pick a server.

Players who want to join to the same game will "land" on that server.

Pros: Scalable

Cons: Need more components, we need to see All active games, we need to a database to store games.

Save this course

Create your own learning path. Save this course to your list so you can find it easily later.
Save

Activities

Coming soon We're preparing activities for Realtime Backend System Design with WebSockets. These are activities you can do either before, during, or after a course.

Career center

Learners who complete Realtime Backend System Design with WebSockets will develop knowledge and skills that may be useful to these careers:

Reading list

We haven't picked any books for this reading list yet.
A practical guide that demonstrates the power of WebSockets in building engaging and responsive real-time web applications. With hands-on examples, it covers topics such as creating chat applications, streaming data, and handling user interactions.
A comprehensive guide to WebSocket programming using Python, offering a deep dive into the protocol's implementation, performance considerations, and common use cases. It includes detailed examples and best practices for building scalable and efficient WebSocket applications.
A comprehensive and up-to-date guide that covers the entire spectrum of WebSocket technology. It provides a deep understanding of the protocol, its implementation, and its applications in various industries. is suitable for both beginners and experienced developers looking to master WebSocket programming.
A specialized book dedicated to WebSocket security, covering threats, vulnerabilities, and best practices for securing WebSocket applications. It provides insights into common attacks, mitigation strategies, and industry standards for ensuring the safety of WebSocket-based communication.
A specialized book that focuses on optimizing the performance of WebSocket applications. It covers advanced techniques, such as reducing latency, maximizing throughput, and handling large-scale deployments. is suitable for experienced developers looking to build highly scalable and performant WebSocket-based systems.
Serves as a comprehensive text for the design of safety-critical, hard real-time embedded systems. It covers fundamental and critical topics with a balance of theoretical and practical knowledge. Organized into well-structured chapters with exercises, it is useful for beginners and provides in-depth theoretical knowledge. It's a good resource for gaining a broad understanding.
Focusing on the design of distributed real-time embedded systems, this book takes a system-level approach. It addresses real-time, distribution, and fault-tolerance issues with a balance of academic concepts and industrial examples. is excellent for advanced undergraduates and graduate students, and it's a strong reference for practitioners working on distributed real-time applications. The third edition includes updates on complexity management, energy awareness, and the Internet of Things.
Provides a comprehensive overview of real-time systems. It covers the theory and practice of real-time systems, and it is suitable for both undergraduate and graduate students.
Focuses on the predictable scheduling algorithms and applications for hard real-time computing systems. It covers the theory and practice of real-time systems development, and it is suitable for both undergraduate and graduate students.
While not solely focused on real-time systems, this book is highly relevant for understanding the challenges of concurrency and synchronization in multiprocessor environments, which are crucial in many modern real-time systems. It provides a strong foundation in concurrent programming concepts essential for designing and implementing real-time applications on multi-core processors.
Provides a systems approach to real-time systems. It covers the theory and practice of real-time systems, and it is suitable for both undergraduate and graduate students.
Provides a practical guide to designing and analyzing real-time systems, offering a holistic, systems-based approach. It covers hardware considerations, software requirements, design, and performance estimation. It is suitable for both students and practicing engineers and valuable reference for its practical tips and code examples. The later editions incorporate object-oriented technologies and agile methodologies.
This book, written in Italian, provides an overview of real-time computing concepts. It valuable resource for Italian-speaking students and professionals who prefer to study the topic in their native language. It covers fundamental principles and techniques in real-time systems.
Offers a blend of theoretical concepts and practical examples with a focus on open-source real-time operating systems (RTOS). It helps designers understand the trade-offs between traditional and modern methods and is particularly useful for those interested in the embedded systems aspect of real-time systems. It provides hands-on knowledge of how RTOS are applied in embedded contexts.
This handbook offers comprehensive coverage of advanced and timely topics in real-time and embedded systems, bringing together contributions from researchers in academia and industry. It examines scheduling, resource management, programming languages, operating systems, and middleware. It's an excellent reference for researchers and professionals seeking in-depth information on various facets of the field.
Provides an in-depth analysis of the requirements for designing and implementing real-time embedded systems, with a focus on programming languages like Ada, Real-Time Java, and Real-Time POSIX. It discusses how these requirements are met by current languages and operating systems and critically evaluates them. It's a valuable resource for understanding the programming language aspects of real-time systems.
Provides a guided tour of real-time systems. It covers the theory and practice of real-time systems, and it is suitable for both undergraduate and graduate students.
Focuses specifically on soft real-time systems, exploring the trade-offs between predictability and flexibility. It delves into scheduling and resource management techniques relevant to systems where missing a deadline is undesirable but not catastrophic. It's a good resource for those interested in this specific area of real-time systems.
Provides a collection of design patterns for real-time systems. It covers the design of real-time systems, and it is suitable for both undergraduate and graduate students.
Comprehensive and foundational text covering the theory and concepts of real-time computing and communication systems. It delves into scheduling, resource access control, and validation techniques. It's widely used as a textbook for senior undergraduate and graduate students and serves as a valuable reference for professionals. While not the most recent, it provides essential background knowledge.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser