Black Friday Deal Hunter: A Flink Agent That Checks the Price
A Flink SQL streaming agent on Confluent Cloud searches real UK shop prices through an MCP server on AWS Lambda, then emails only genuine best deals or fake discounts.
Overview
You see “£299.99, was £400” next to a Dyson Airwrap and you wonder whether it is a real deal. Checking means opening ten shop tabs and comparing by eye. Two days before Black Friday, a Flink agent did that check for five gift ideas and returned three genuine best deals, one ordinary price, and one product it refused to judge because it had too little to compare.
Think of a friend who hates being ripped off. You hand them a Christmas list. They check every shop, and they text you only when something is worth knowing. This repo is that friend, built as a stream: each product on a Kafka topic wakes an agent, the agent searches real prices through a tool, and a verdict comes out the other end.
It borrows its shape from Confluent’s price-matching Lab 1, where an agent compares one competitor. Here it compares many shops, and the MCP server is ours, built with Terraform, so anyone can run the demo without a workshop token.
How it works
- Input. A Python producer puts five gift ideas on the
wanted_productstopic. - The agent.
CREATE AGENTin Flink SQL, run on every row byAI_RUN_AGENTinside a continuous job. The model is Confluent-hostedanthropic.claude-sonnet-4-6, so there are no Bedrock keys. - Two tools on an MCP server, one AWS Lambda behind a Function URL.
search_pricescalls SerpAPI’s Google Shopping search for UK results and works out the median, the gap to the median, and any claimed saving.send_emailsends through Amazon SES. - The rules. The agent applies them to numbers the tool returned.
BEST_DEALneeds the cheapest listing at least 10% below the median.FAKE_DISCOUNTneeds a claimed saving of 20% or more with the price less than 5% below the median. OtherwiseOK_PRICE, orNO_DATA. - Output. One verdict per product on the
deal_verdictstopic, and one email per best deal or fake discount.
wanted_products ──► Flink job ──► AI_RUN_AGENT(deal_hunter)
(Python) (Confluent) │
▼
MCP server (AWS Lambda)
┌────────────────────┴───────────────────┐
search_prices send_email
SerpAPI, UK shops Amazon SES
median, gap, claimed saving (best deals only)
│
▼
deal_verdicts topic
What it demonstrates
On the first real run, on 25 November 2026:
- Apple AirPods Pro:
BEST_DEAL. £154.80 against a median of £183.99. - Nintendo Switch 2:
OK_PRICE. £399.99 against £440.99, 9.3% below, just short of the 10% bar. - LEGO City advent calendar:
BEST_DEAL. £18.39 against £26.13. - Dyson Airwrap:
BEST_DEAL. £299.99 against £355.36. Its claimed 25% saving was real, so it was not flagged as fake. - Ninja air fryer:
NO_DATA. Fewer than four comparable listings, so the agent did not guess.
That is three best deals, one ordinary price, one refusal, and no fake discounts. Three runs gave the same verdicts. The fake-discount branch has never fired on real data, so it is untested. Prices are a snapshot and will have moved.
Technical details
- Stack: Terraform (Confluent and AWS providers), Flink SQL with
CREATE CONNECTION,CREATE MODEL,CREATE TOOLandCREATE AGENT, a Python Lambda, and Python clients for the producer and the verdict viewer. - One command each:
make upbuilds the cluster, the Lambda, the SES identity and the Flink statements.make demoruns the story.make downremoves it. - Where it runs: AWS
eu-west-2, a Confluent Standard cluster, and a Flink compute pool capped at 5 CFU. The cluster and the running job bill by the hour until you destroy them. - The MCP token is generated by Terraform (
random_password) and passed into the Flink connection. The SerpAPI key lives only in the Lambda environment, so it never appears in an agent prompt. - Cost of a run: five SerpAPI searches, so the free plan’s 250 a month goes a long way.
Challenges & lessons
- Raw shopping results lie. The first search for a PlayStation put a £40.22 “Sony Playstation Console” first, 78% below the median. A trusting agent would have announced a best-ever deal on an old or used console. The Lambda now drops second-hand items, marketplaces, resale shops, importers and third-party sellers, requires every word of the query in the title, and trims prices below half the median.
- Do the sums in code. The model decides. The Lambda calculates. Every number in a verdict comes from the tool, so there is nothing for the model to get wrong about a median.
- Refusing is a result. Fewer than four comparable listings returns
found: false, and the agent saysNO_DATA. Wording matters as much: “LEGO advent calendar” matched nothing useful, while “LEGO City advent calendar” gave 14 listings. - “Sent” is not “delivered”, and delivered is not seen. The agent reported its emails as sent, because the tool returned success. Nothing showed up in the inbox. The Lambda log and SES statistics proved the mail left AWS with no bounces. All six alerts from two runs were in the Spam folder, because the sender had no DKIM or SPF behind it. The model cannot know any of that, so the demo does not claim delivery.
- A running job cannot be replaced. Changing text inside a Flink statement makes Terraform want to replace it, and the API never returns the connection token, so that statement always looks changed. A re-created
CREATE TABLE ... ASjob would fail because its table already exists.ignore_changeson the statement fixes it, and rule changes live in the Lambda instead. - Public Function URLs need two permissions, applied in order. Terraform’s own permission and mine collided in a
ResourceConflictExceptionon the first apply. The provider addslambda:InvokeFunctionUrlitself, so only the second permission is declared, after the URL exists.