← Blog

Winning the PRTH Hackathon Solo: Building a Real-Time Rule Engine

On 23 November 2022, I won the PRTH Hackathon, taking home a prize of Rs 75,000. What made the experience especially memorable was the format: I participated alone, competing against more than 30 teams, most made up of three to four members.

My project was a configurable rule engine designed to evaluate incoming records against business rules and produce actions when conditions matched. Rather than hard-coding every business decision in application logic, I wanted the rules to be expressed as data—making them easier to configure, inspect, and extend.

Expressing business logic as JSON

I represented rules as JSON objects containing a name, conditions, and an event definition. Conditions supported boolean composition such as all and any, along with comparisons against record facts. For example, a rule could detect a high temperature when a device was active, or identify low humidity combined with high pressure.

This separation between rule definitions and the execution engine is useful in systems where thresholds and business policies change more often than the underlying application code.

How the engine evaluates records

The core is organised around an Engine, Rule, Condition, and Almanac. At runtime, a record supplies facts. The engine evaluates the configured conditions, tracks the results, and emits an event when a rule succeeds. The event includes a type and optional parameters, allowing downstream code to decide what action to take.

Rules can be prioritised, and condition evaluation supports all, any, and not logic. The engine also exposes extension points for custom operators and operator decorators, so domain-specific comparisons can be added without rewriting the evaluation flow.

Processing records concurrently

To handle batches of input, I built a worker layer around the engine. Workers consume records from an asynchronous iterator, evaluate them, and collect the original record, triggered actions, and valid conditions. The runner starts multiple workers against the shared iterator and waits for them to finish, then writes the processed results to JSON.

This approach demonstrates how independent records can be distributed across concurrent asynchronous workers while keeping the rule evaluation component separate from the input mechanism.

Taking it towards streaming with Kafka

I also documented a Kafka integration using KafkaJS. A consumer subscribes to an input topic, parses each message, passes the record through the worker and rule engine, and publishes the evaluation output to a separate topic. This creates a stream-processing shape: input events enter Kafka, rules evaluate them, and downstream consumers receive the resulting actions and matched conditions.

What I took away

Building the project solo under hackathon constraints pushed me to make practical architecture choices, connect multiple components, and document how to run the system. The experience reinforced the value of configurable logic, clear separation of concerns, asynchronous processing, and event-driven integration.

Winning PRTH Hackathon was a meaningful milestone—not just for the prize, but for proving that I could take an idea from rule definition through execution and towards real-time processing independently.

Project and implementation notes: Rule Engine repository and documentation · Source code