← All projects

Case study

Payment Intelligence Platform

Streaming payment analytics with a deterministic fast path and a governed LLM layer

A payment event stream flows through Kafka and three Spark jobs into ClickHouse. A FastAPI layer serves governed endpoints. On top sits a question interface with two paths: a deterministic router that answers common questions instantly with no LLM, and an LLM reasoning layer that can only call those same governed endpoints, never write SQL. It is complete and tested locally on simulated data, and hosting is the remaining step.

Highlights

  • Tier 1: semantic router answers 8 fixed question types with no LLM
  • Tier 2: LLM orchestrates 5 governed API tools, never generates SQL
  • Three Spark Structured Streaming jobs (summary, risk, pipeline health)
  • ClickHouse ReplacingMergeTree with FINAL enforced by unit tests
  • Server-issued HttpOnly session, identity upgrade in place, session id rotation
  • Provider orchestrator with circuit breaker and automatic failover

How it works

  1. 1. Simulated payment events enter Kafka

    An event simulator produces schema-checked payment events (default 10 per second across 50 merchants). A webhook receiver for PayPal Sandbox exists too, with HMAC signature verification. Events are keyed by merchant so each merchant stays on one partition.

  2. 2. Three Spark jobs build the data products

    Separate Spark Structured Streaming jobs compute merchant payment summaries in 1-minute windows, risk signals in 5-minute windows against a historical baseline, and pipeline health snapshots. Delivery is at-least-once, with watermarks for late events and checkpoints for crash recovery.

  3. 3. ClickHouse stores and deduplicates

    Results land in ReplacingMergeTree tables, so a repeated write of the same window is harmless. The price is that every read must use FINAL to see deduplicated rows, so a unit test enforces it on the query layer.

  4. 4. FastAPI serves governed endpoints

    The API owns the business definitions. Queries are kept in a dedicated query layer with typed parameters, and a service layer sits above them. Dashboards and the question interface both go through the same services.

  5. 5. Tier 1: the deterministic fast path

    A semantic router embeds the question with a small sentence-transformer model and compares it with 8 governed intents. Above the confidence threshold it calls the matching service directly, with no LLM involved. Below it, the question falls through to Tier 2.

  6. 6. Tier 2: governed LLM reasoning

    For questions that need several steps, an LLM chooses among 5 tools that wrap the same services. It never writes SQL and never touches the database. The loop is bounded by a tool-call ceiling and a token limit, tool results are truncated, and the system abstains when it cannot answer. A provider orchestrator with a circuit breaker fails over between providers, and it works with any LLM provider.

  7. 7. Sessions and secrets

    Visitors get a server-issued session carried in an HttpOnly cookie. Guest or Google identity upgrades the same session, and the internal session id rotates on logout. The internal API key never reaches the browser: dashboard data is fetched server-side.

  8. 8. Status

    Feature-complete and tested locally, about 95% done. Both the fast path and the LLM reasoning path work end to end. Hosting is the remaining step, so there is no public URL yet. The data is simulated.

Explore this project