
This project-based Linux IPC course teaches building a pub-sub system with C or C++, covering multithreading, synchronization, sockets, shared memory, message queues, byte-by-byte messages, and queues, linked lists, hash maps.
Explore how publishers publish messages and how the coordinator distributes them. Observe how subscribers express interest, decoupling enables dynamic join and leave.
Explore how pub-sub systems enable decoupled, real-time communication with topics, publishers, subscribers, and a central broker across social media, IoT, ecommerce, and distributed task processing.
Set up a development environment using git for version control, fork the course repository, and configure VS Code on Ubuntu for a C/C++ pub-sub project with Makefile automation and debugging.
Explore the design of a Linux IPC pub-sub system, detailing broker registration, unique IDs, publisher and subscriber databases, message distribution queues, and IPC channel choices for delivery.
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard a1075840b136450e245cca5800edafb00d8dfa72
<now browse the code as you like >
To restore the code repo to latest, use git pull
Design coordinator data structures for publishers, subscribers, and their relationships, enabling registration, tracking of publisher and message IDs, and subscriber mappings in a linux ipc pub-sub system.
Implement management APIs for the pub-sub coordinator to insert, update, and delete publishers, subscribers, and publisher-subscriber records using unordered maps, based on the coordinator db header with 11 functions.
Launch the coordinator as a listener thread plus a configurable set of distribution threads using pthreads, handling a UDP port and preparing for message distribution to subscribers.
Create a makefile to build the static library lib code dot a and a coordinator executable with g++ and pthread, compiling coordinator start dot o and coordinator db dot o.
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard 7cbb7a4e0c6290ef4afdd6760ac8bbb465b098a0
<now browse the code as you like >
To restore the code repo to latest, use git pull
Implement the cmsg_t structure in the common directory for a Linux IPC pub-sub system, detailing message id, type, sub type, priority, code, id, and a TLV buffer.
Attach is the tlv.h hdr file. Put it in Libs dir.
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard df66e284134efc94e04e7e5ea40d017ae53c2e1c
<now browse the code as you like >
To restore the code repo to latest, use git pull
Implement the coordinator listener thread to bind a udp socket on a defined ip and port, receive cmsg messages, and process publisher and subscriber messages with replies.
Explain the publisher registration flow in a Linux IPC pub-sub system: parse the name TLV, update the coordinator's publisher database, and return a unique publisher ID.
Implement a socket-based publisher and subscriber as separate processes, linked to a client library exposing register and unregister APIs to interact with the coordinator over a socket interface.
Implement a socket based publisher that registers with a coordinator over a UDP socket on port 50000, receives a publisher ID, and can unregister via the coordinator Unregister API.
Implement client library APIs for (un)registration with the broker in a linux ipc pub-sub project, building a TLV-backed message and dispatching it to the coordinator.
Update the makefile to compile a static client library libclient.a and a publisher socket executable, linking the publisher with the client library and required object files.
Start the coordinator, launch multiple publishers on distinct ports, and observe the coordinator assign IDs and update its database, then send unregister messages to verify registration handling.
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard 7ff3e5e5f5e1ef4378795edecf97ca04ddede191
<now browse the code as you like >
To restore the code repo to latest, use git pull
Implement coordinator changes to handle sub message add and delete for both publisher and subscriber, introducing publisher publish/unpublish and subscriber subscribe/unsubscribe APIs that update the coordinator's databases.
Test the pub-sub ipc system by running the coordinator, publishers, and subscribers across ports 50,000–50,003, publishing and unsubscribing messages. Verify coordinator databases reflect registrations and subscriptions during changes.
This section outlines building a distribution system for an asynchronous pub-sub setup, showing how the coordinator enqueues messages into distribution queues and how the distribution thread dispatches them to subscribers.
Design a message distribution system with a coordinator listener and a distribution thread using high, medium, and low priority sub-queues to dispatch publisher messages to subscribers in a producer-consumer flow.
Update Makefile :
COORDINATOR_OBJS=CoordinatorCore/coord_start.o \
CoordinatorCore/coordDb.o \
CoordinatorCore/coord_msg.o \
Common/cmsgOp.o \
CoordinatorCore/CoordDistribution.o
CoordinatorCore/CoordDistribution.o:CoordinatorCore/CoordDistribution.cpp
${CC} ${CFLAGS} CoordinatorCore/CoordDistribution.cpp -o CoordinatorCore/CoordDistribution.o
design a coordinator distribution queue with priority sub-queues using vectors; each entry pairs a message with its subscriber, while NQ and DQ use a mutex and DQ blocks when empty.
Implement reference counting for the Cmsg object to avoid premature deletion when queued for multiple subscribers in a distribution queue, using increase and dereference APIs, like a shared pointer.
Implement and mutex-protect enqueue and dequeue in the coordinator distribution queue, signal the distribution thread on new data, and release all vector data and resources to complete pub-sub integration.
Publishers send data messages to the coordinator for distribution by the message distribution system, using SUB_MSG_DATA with type 100 and a TLV payload, bridged by a coordinator API.
The coordinator launches a listener and multiple distribution threads, creates distribution queues, and uses a round-robin scheme to dispatch messages to subscribers, enabling load-balanced pub-sub distribution.
The coordinator receives data from the publisher and forwards the cmsg to the distribution system for subscriber delivery using a round-robin queue.
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard bbceea14d92cd10ac995e14751851e93fa895291
<now browse the code as you like >
To restore the code repo to latest, use git pull
After the end of this section of the course, You can browse the snapshot of the code by following the below steps :
git clone <github URL to the pub-sub repo>
cd pub-sub
git reset --hard 68ebe3932eefe0751e8af082d024a26247d54aa6
<now browse the code as you like >
To restore the code repo to latest, use git pull
Implement an api in client and cpp that lets subscribers report their ipc channel to the coordinator, encoding udp ip and port or unix socket name in a cmsg tlv.
Show how the coordinator processes a subscriber’s IPC channel add request by updating the subscriber database with the chosen IPC method, handling UDP sockets, TLVs, and IP:port details.
Complete the coordinator_dispatch function for UDP socket based communication, sending messages to the subscriber via sendto, reusing or creating the socket as needed, with shared memory removed.
Enhance the subscriber socket example to register its IPC channel with the coordinator, wait for data messages, and decode TLV data in a final pub-sub demonstration.
Demonstrate an asynchronous pub-sub flow by coordinating a publisher and subscriber through a central coordinator, using UDP sockets to dispatch data messages from publisher to subscriber.
Explore the tlv concept—type, length, value—packing data flexibly, with one-byte type and length fields, enabling recipients to ignore unknown data and understand unit sizes.
Parse a tlv buffer by reading its type and length, compute the number of value units, and loop through strings while advancing to the next tlv without overrunning memory.
Develop an iterative macro to parse a TLV buffer, extracting type, length, and value for each TLV while guarding against buffer overruns.
Explore building an asynchronous pub-sub system on Linux IPC, as a bonus module, to enhance understanding of inter-process communication patterns.
Pub/Sub System in C/C++: Course Overview
Unlock the Power of Asynchronous Communication with Pub/Sub in C/C++
Welcome to this comprehensive course on designing and implementing a robust Publish-Subscribe (Pub/Sub) System using C/C++. This course is tailored for developers who aspire to master the principles of real-time messaging systems and understand how to build scalable, efficient, and loosely-coupled communication architectures from scratch.
What is a Pub/Sub System?
A Publish-Subscribe system is a messaging paradigm that decouples the sender (publisher) from the receiver (subscriber). It allows for seamless communication between multiple components by enabling subscribers to receive updates on topics they are interested in, without being directly tied to the publisher. This design is widely used in real-world applications like:
Messaging Systems: RabbitMQ, Kafka
Microservices Communication
IoT and Real-Time Event Systems
What You Will Learn
In this course, we’ll build a fully-functional Pub/Sub system using C/C++, covering every essential concept step by step:
Understanding Pub/Sub Fundamentals
How publishers and subscribers interact through topics.
Decoupling communication with message brokers.
Designing the Architecture
Implementing message queues for efficient data flow.
Managing subscribers and topic registries.
Handling asynchronous communication and thread safety.
Building Core Components in C/C++
Publisher: A module to publish messages to specific topics.
Subscriber: A module to subscribe to topics and receive updates.
Broker: The central hub to manage topics, deliver messages, and coordinate between publishers and subscribers.
Optimizing for Performance
Implementing thread pools for parallel processing.
Minimizing latency with efficient data structures.
Message Prioritisation:
Allow publishers to assign priorities to messages.
The distributor delivers higher-priority messages first to subscribers.
Heartbeat and Health Checks:
Implement a heartbeat mechanism to check the liveness of publishers and subscribers.
Detect and remove inactive entities automatically.
Dynamic Scaling:
Add auto-scaling support to adjust resources based on system load.
Message Encryption:
Encrypt messages to secure data in transit and at rest.
Who Should Enroll?
Developers interested in building high-performance messaging systems.
C/C++ Programmers seeking hands-on experience with real-world software design patterns.
Software Architects aiming to design scalable and maintainable systems.
Learners exploring the implementation of microservices and event-driven architectures.
Why Take This Course?
By the end of this course, you’ll have the skills and confidence to:
Design and implement your own Pub/Sub system in C/C++.
Understand the principles behind distributed messaging systems.
Solve real-world problems with efficient communication architectures.
Join now and start your journey towards mastering Pub/Sub systems in C/C++. Let’s build something amazing together!