Inspiration
Small and medium businesses lose an estimated 5-10% of revenue to failed payments every month because of expired cards, declined transactions, and insufficient funds. Most SME owners discover these failures too late, buried in Stripe dashboards they barely have time to check. I asked: what if an AI agent could watch your payment stream 24/7, detect problems the moment they happen, and fix them with your approval?
The breakthrough insight was that CockroachDB could serve as both the operational database AND the AI agent's memory - storing transactions, customer data, vector embeddings, and decision history in one distributed system.
What it does
LedgerMind is an AI-powered payment operations agent for SMEs. It:
- Detects payment failures in real-time and identifies patterns (card declined spikes, expired card clusters, at-risk customers).
- Decides what to do by analyzing failure data, comparing against learned baselines, and referencing past decisions stored as vector embeddings in CockroachDB.
- Recovers revenue by creating targeted recovery campaigns, with human-in-the-loop approval before any action is taken.
Key features:
- Morning Daily Brief : Opens with a smart headline, health score, action items, and 7-day revenue trend. No clicking required.
- Conversational AI Agent : Ask "why are payments failing?" in plain English and get data-backed answers from CockroachDB.
- Human-in-the-Loop Approvals : Agent recommends actions but never executes without SME owner's explicit approval.
- Stripe Integration : Real payment data flows from Stripe into CockroachDB and surfaces in the dashboard.
- Semantic Memory : Agent stores every observation and decision as vector embeddings, enabling "find similar past incidents" retrieval.
How we built it
Architecture:
- CockroachDB Cloud (Serverless, eu-west-2) — Single source of truth for transactions, customers, agent memory (pgvector VECTOR(1024) columns with HNSW indexes), and decision history.
- Amazon Bedrock - Claude for agent reasoning, Titan Embeddings V2 for 1024-dim vectors.
- AWS ECS Fargate - Python/FastAPI backend containerized and deployed.
- AWS API Gateway - HTTP API routing to ECS via Cloud Map service discovery.
- AWS Amplify - React/TypeScript frontend with Cognito authentication.
- Stripe - Test mode integration for real payment data.
CockroachDB Tools Used:
- Distributed Vector Indexing - VECTOR(1024) columns on
agent_memoryandagent_decisionstables with HNSW indexes (m=16, ef_construction=64) for cosine similarity search. The agent uses this to find similar past incidents and retrieve relevant context for reasoning. - CockroachDB Cloud Managed MCP Server - MCP compatible tool interface exposing structured data access (query_transactions, get_failure_analysis, search_similar_memories) with read-only safety and audit logging.
Challenges we ran into
- CockroachDB + asyncpg SSL : CockroachDB Cloud requires SSL but asyncpg doesn't support
sslmodein the connection URL. Had to strip the parameter and pass an SSL context object viaconnect_args. - Version string parsing : SQLAlchemy's PostgreSQL dialect choked on CockroachDB's version string. Monkey-patched
PGDialect_asyncpg._get_server_version_infoto return(14, 0, 0)on parse failure. - ECS + Cloud Map port registration : Cloud Map service discovery doesn't include port by default. Every ECS deployment required manual registration of port 8000 — a surprising gap in the AWS integration.
- Amplify build path : The git repo has a space in the path ("CockroachDB hackathon/frontend") which broke the Amplify build multiple times. Had to use
appRootin the build spec. - Stripe test mode declined cards : Stripe's newer API doesn't return PaymentIntent objects on CardError exceptions, so we had to synthesize failed transaction data separately.
Accomplishments that we're proud of
- True E2E deployment : Not a localhost demo. Real AWS infrastructure (47 resources), real CockroachDB Cloud cluster, real Stripe integration, live at
main.dhz2dy59bebbh.amplifyapp.com. - CockroachDB as agentic memory : Proved that one database can handle operational queries, vector similarity search, and AI decision tracking without needing Pinecone/Weaviate/etc.
- The Daily Brief : An SME owner opens the app and immediately knows: am I making money, is anything broken, and what do I need to do. Zero clicks required.
- Human-in-the-loop that works : The approval flow goes from agent recommendation → pending decision in CockroachDB → visible in Approvals UI → approve/reject → execution. Full loop verified with E2E tests.
- realistic SME scenarios all passing : Performance check, failure investigation, recovery campaign with approval, revenue forecasting, and churn risk analysis, all powered by real CockroachDB queries.
What we learned
- CockroachDB's pgvector support is production-ready : HNSW indexes with cosine distance work seamlessly. The idea of co-locating vector embeddings with operational data eliminates an entire class of consistency problems.
- The MCP pattern is powerful for agent architecture : Structuring database access as MCP tools (with clear input schemas and read-only defaults) makes AI agents safer and more auditable.
- Human-in-the-loop builds trust: An AI that says "here's what I'd do, shall I proceed?" is dramatically more trustworthy than one that just acts. The approval workflow is the feature, not a constraint.
What's next for LedgerMind
- Real-time Stripe webhooks : Replace batch sync with live webhook ingestion so failures appear in the agent's analysis within seconds.
- Actual campaign execution : Connect approved recovery campaigns to email providers (SendGrid/SES) to send real card update links.
- Time-series forecasting : Replace the static +12% projection with proper ML forecasting using CockroachDB's historical data.
- CockroachDB Changefeeds : Use
CREATE CHANGEFEED FOR transactionsto stream new payments directly to the agent for real-time anomaly detection. - Multi-tenant isolation : Apply
sme_idfiltering consistently so multiple businesses can use the platform independently. - Mobile push notifications : Send the daily brief as a morning notification so owners don't even need to open the app
Built With
- amazon-web-services
- bedrock
- cockroachdb
- docker
- react
- serverless
- stripe
- terraform
Log in or sign up for Devpost to join the conversation.