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.

Why EDA for a Trivia Application?

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:

  • Scalability for concurrent players: EDA’s scalability allows the application to effortlessly handle a large number of concurrent players, and multiple trivia games running simultaneously while maintaining smooth gameplay without any performance bottlenecks.
  • Real-time responsiveness: Trivia games thrive on real-time interactions. EDA facilitates the rapid propagation of events, ensuring instant updates to all players, regardless of their location or device.
  • Real-time updates: Trivia games thrive on real-time interactions and instant feedback. EDA enables the rapid propagation of events, ensuring that all players receive immediate updates on questions, answers, and scores, creating a highly responsive and engaging gaming experience.
  • Dynamic game state: Trivia games often have dynamic game states with changing questions, timers, and player interactions. EDA’s event-driven nature allows the application to adapt quickly to these changes, keeping all players synchronized and immersed in the game.
  • Seamless multiplayer support: Trivia applications are typically multiplayer-oriented. EDA’s event-driven communication enables smooth coordination between players, ensuring that their actions and responses are distributed efficiently to all participants in real time.
  • Instant scorecards and leaderboards: EDA enables real-time calculation and distribution of scores as players answer questions. This immediate feedback provides players with instant results and updates the leaderboards on-the-fly, intensifying the competition and excitement.
  • Event logging and auditing: Trivia applications may require event logging and auditing for various purposes, such as reviewing game sessions, detecting cheating, or analyzing player behavior. EDA facilitates easy event capturing and recording, aiding in monitoring and analysis.
  • Enhanced interactivity: EDA fosters interactive and dynamic gameplay by allowing players to trigger events that may influence the game’s progression or outcome and interact with other players making the Trivia application more immersive and enjoyable.

Now let’s get into the details.

Fireball Trivia – What is it?

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.

Application Environment – Trivia Manager

MERN (MongoDB, Express, React, and Node) stack is employed for Trivia Management, a web application.

  • Uses Solace Node.js library for interaction with Solace PubSub+ Event Broker
  • Uses secured WebSocket endpoint to connect with the Solace PubSub+ Event Broker

 Game Interface – Trivia Game

A simple HTML/JS-based single-page application provides the Trivia Controller and Trivia Game interfaces.

  • Uses Solace JavaScript library for interaction with Solace PubSub+ Event Broker
  • Uses secured MQTT endpoint to connect with the Solace PubSub+ Event Broker

Following are some of the features supported by the Fireball Trivia implementation.

  1. Execution of multiple trivia parallelly
  2. Interaction between controller and participants within the trivia such as invite, join, sending questions and collecting responses, in-game chat etc.
  3. Real-time analysis of responses and sharing updates on the score, winner along with game stats.

Fireball Trivia Components

fireball trivia diagram

Trivia Console

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.

Trivia Controller

Trivia Controller is a simple HTML/JS application that starts and manages trivia games. It operates as a single-page app and relies on event-based interactions using the Solace JavaScript client with the paho-mqtt library.

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.

Trivia Game

Trivia Game is a mobile-friendly HTML/JS app that starts and facilitates trivia sessions. It operates as a single-page application that can run on both web and mobile browsers and relies on event-based interactions using the Solace JavaScript client with the paho-mqtt library.

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.

Lessons Uncovered

Throughout the process of building the Trivia application with EDA and Solace PubSub+, valuable insights were gained on the following topics.

Event Modeling

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.

 

Event Choreography

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.

diagram 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.

PubSub+ Benefits

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:

  • Real-time event distribution
  • Scalability and performance
  • Dynamic topic routing
  • Reliability and fault-tolerance
  • APIs for popular languages
  • Multi-protocol support

Final Product – The Fireball Trivia App

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.

The trivia controller and game apps are a single-page JavaScript applications that utilizes the publish-subscribe and request-reply message exchange patterns that extensively makes use of topic hierarchy and wildcard subscriptions supporting features like start trivia, invite members, join members, send questions, collect responses, and show results.

trivia controller and game apps images

Conclusion

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! 🎉

Giri Venkatesan
Giri Venkatesan

Giri is a developer advocate with extensive experience in various technical domains, including integration and master data management. He started his engineering journey in the classic EAI & B2B Integration space and has been a part of the integration evolution culminating in modern EDA, microservices, Spring, and other low-code/no-code frameworks. He has a keen interest in building and promoting creative solutions and is a huge fan of open-source standards and applications. He is excited to identify and explore tools and frameworks to aid businesses in their quest for achieving efficiency and increased productivity.