Case study · Oil and gas company

An expert system that scaled with the business

I built an expert system that captured specialist knowledge as explicit rules, so decisions that once waited on a few senior people could be made consistently across a fast-growing operation.

  • 37sites, up from 4, with no re-architecture
  • 15 mindecision time, down from 3 days
  • 1,850rules in production
  • $8.5Msaved a year

Challenge

  • Key operational and commercial decisions depended on a small group of experts, which became a bottleneck as the business grew.
  • Decisions varied between sites and shifts, and the reasoning behind them was rarely written down.
  • The system had to grow with the company: more sites, more products, more users and more rules, without slowing down.

What I built

  • A rules engine and knowledge base, written with the domain experts, with every rule versioned, tested and traceable to its owner.
  • An explanation layer showing which rules fired and why, so users could trust and audit each recommendation.
  • APIs connecting the system to operational, inventory and ERP data, so recommendations used live figures.
  • A modular, multi-tenant design so new sites and business lines were added through configuration, not code changes.

Stack

Python, Java, Drools rules engine, PostgreSQL, Redis, RabbitMQ, REST and GraphQL APIs, React for the admin console, Docker, Kubernetes, AWS.

System design

The rules hold the expertise and the decision service applies them. Every answer can be traced back to the rules and data that produced it.

Every answer can be traced back to the rules and data that produced itCI runs every rule testPython connectorsRabbitMQ eventsapprove releasesKnowledge baseDrools rule files anddecision tables in GitVersioned releaseOperational, inventory,pricing and ERP dataPostgreSQLRedisfrequently used factsDecision serviceJava Spring Boot, statelessDrools sessionExplanation traceEvery decision loggedrule version and inputsAdmin consoleReactNightly batchre-evaluationsRabbitMQ workers
  1. Knowledge base: rules are written as Drools rule files and decision tables, laid out like spreadsheets so experts can read them. They are stored in Git, and each rule has an ID, an owner, a version and its own test cases. CI runs every rule test before a rule set is packaged as a versioned release.
  2. Fact gathering: Python connectors pull live operational, inventory, pricing and ERP data into PostgreSQL. Redis caches frequently used facts, and RabbitMQ events signal when source data changes so affected decisions can be re-run.
  3. Decision service: a Java Spring Boot service loads the facts for a case, runs the current rule set in a stateless Drools session and returns a recommendation. Because sessions hold no state between requests, the service scales horizontally on Kubernetes.
  4. Explanation trace: a listener on the engine records every rule that fired, in order, with the facts it matched. The trace is stored with the decision, so the console can show exactly why a recommendation was made.
  5. Multi-tenancy: each site's rule set is built in layers: company-wide rules, then business-line rules, then site overrides. Every fact and decision carries a tenant ID. Adding a site means configuration and data mapping, not new code.
  6. Admin console: in a React console, experts review rules, replay historical cases against a draft rule version to see what would change, and approve releases.
  7. Audit and batch: every decision is logged with its rule version and inputs. Nightly batch re-evaluations run through RabbitMQ workers, so changes in data show up the next morning.

Results

  • Growth absorbed: from 4 to 37 sites and from 60 to 2,400 users, with no re-architecture
  • Decision time: from 3 days down to 15 minutes
  • Knowledge captured: 1,850 rules in production, each with tests and a named owner
  • Business impact: 70% fewer escalations to senior experts, about $8.5M saved a year
Back to Work & Research