Welcome to an exciting exploration into the world of event-driven architecture (EDA) and how it revolutionizes the way we build and scale interactive applications. In this blog, I will share my journey to create a Trivia application – Fireball Trivia, leveraging the power of Solace PubSub+ Platform. Discover how EDA, combined with a robust pub-sub system, unlocks new possibilities for seamless real-time interactions, responsiveness, and scalability.
EDA is a paradigm where events are the primary means of communication between components or services within a system. Unlike traditional request-response models, EDA fosters loose coupling and enables reactive responses to events as they occur. In the context of a trivia application, EDA offers several compelling advantages:
Now let’s get into the details.
Fireball Trivia is a multi-trivia, multi-player game that supports creating, managing, and running trivia games. Trivia supports any number of players to join and participate in the game at runtime. At the end of the game, it presents them with personal and overall performance results. Optionally, it can also collect information from the top performers for rewards.
MERN (MongoDB, Express, React, and Node) stack is employed for Trivia Management, a web application.
A simple HTML/JS-based single-page application provides the Trivia Controller and Trivia Game interfaces.
Following are some of the features supported by the Fireball Trivia implementation.
Trivia Console is a web application that manages and administers trivia. It connects the front end with the back end using REST APIs. It handles user authentication and stores trivia-related data (questions, categories) in a MongoDB database.
To monitor all trivia activities in real-time, Trivia Console utilizes the Solace Node.js client library to create a PubSub+ client on the broker. This includes tracking question publishing, answer collection, scorecard updates, leaderboard information, and live chat among participants. It acts as an activity monitor, capturing all event interactions and directing them to specific trivia participants (users). Trivia Console also sends targeted events to specific trivia sessions using Solace Topic subscriptions, wildcards, and variables to ensure the correct events reach the right users
Trivia Console maintains metrics such as scorecards and leaderboards throughout the game. These updates are published to all participants, including the controller in real-time.
When the trivia admin (owner) logs into Trivia Console, they gain access to the controller page and game page URLs. By launching the trivia, they can share the game page URL with participants through a link or QR code.
Trivia Controller subscribes to all trivia events, including question publishing, answer collection, scorecard updates, leaderboard information, and real-time chat among participants. The controller page displays an interactive and visually appealing game output that updates in real time as the trivia progresses.
When the trivia owner initiates the trivia game, questions are streamed to the game client. As participants respond or choose not skip, their actions are captured and published as events to the broker.
The game page showcases an interactive and visually engaging output that refreshes in real time, keeping participants fully immersed in the trivia experience.
Throughout the process of building the Trivia application with EDA and Solace PubSub+, valuable insights were gained on the following topics.
Event Modeling is of utmost importance in EDA as it forms the foundation for how events are designed, structured, and communicated within the system. Event Modeling defines the way information is exchanged, triggers actions, and enables collaboration among different components or services in an event-driven application.
First, identify the various types of events that occurs in a Trivia game, define the schema and its attributes associated with each event, and establish relationships between events. Define Applications with distinct responsibilities such as Console, Controller, and the Trivia Game. Associate events with appropriate publish-subscribe permissions to the applications and visualize the event flow in the modeled event mesh.
In EDA, the sequence and order of interactions between components are determined by the events themselves, rather than being dictated by a centralized process or workflow engine. This makes EDA well-suited for complex, distributed systems where components need to react to events from various sources and collaborate to achieve business goals.
Fireball Trivia is designed to support multiple trivia games running simultaneously, while ensuring that the interactions between the controller and the game are restricted to that particular game. There are various aspects of the trivia game that requires coordinated interactions and responses such as announcing the start of a game (sending invites), collating the participants (join confirmation), sending questions to participants of the game (broadcast) and collecting responses from the participants and supporting an in-game chat among participants.
Here is a quick snapshot of Fireball Trivia applications and their interactions on identified events.
Solace PubSub+ Event Portal simplifies and enhances event modeling exercise with its centralized platform for event definition, visualization, management, and governance. This makes It easy to design and implement required components with absolute clarity on interactions and flow of events at runtime.
Discover the unique features and benefits of Solace PubSub+ Platform, such as its ability to handle large message volumes, support different message exchange patterns, and support for different protocols.
The choice of language and protocol is always determined by the implementors preference and suitability. With Solace’s rich support for variety of language APIs and native protocol support makes it attractive and easy to use. Some of the benefits realized by using a Broker to build a Trivia application are:
As mentioned earlier, all the components of the trivia app are built as a responsive web application that can run on both web and mobile browsers. Here are few screenshots of the app.
The trivia console is a simple web application that helps to build questions, categorize them, and create and execute trivia.
In conclusion, building a trivia app using Solace PubSub+ has been an exciting journey into the realm of real-time messaging and EDA. Leveraging the power of PubSub+ Event Broker has enabled a highly scalable, reliable, and engaging trivia experience for our users.
The robust messaging infrastructure of PubSub+ Event Broker allowed delivery of trivia questions instantly to a large number of participants, ensuring a seamless and immersive trivia session. With high message throughput and dynamic topic routing, Solace’s broker facilitated efficient event distribution, even during peak loads.
The flexibility and multi-protocol support of PubSub+ Event Broker caters to a diverse audience, accommodating various devices and platforms. The trivia application discussed in this blog is available as open source on GitHub at https://github.com/SolaceLabs/event-driven-trivia
Happy Trivia-ing! 🎉