More
Сhoose

Applied

Engineering

Results

samuel-torres.com

Caravana — Points & In-Store Redemption Platform

Read the case study
Retail point-of-sale terminal, representing the in-store redemption flow
MySQL · PHP · Concurrency · Multi-Timezone
2026
Role

Backend engineering, concurrency design and AI-assisted development for a real-money, multi-store, multi-day redemption system.

Core stack

PHP · MySQL · JavaScript · React (floor app) · Claude Code (AI-assisted engineering) · IANA time zones

Context

Caravana needed to run a points-and-prize-redemption campaign on the sales floor, across stores from several retail chains, over several consecutive days. There was real money involved: a double charge isn't a bug ticket, it's an angry customer at the counter with a line behind them. The system had to hold six constraints at once — real money, unreliable in-store WiFi, non-technical operators in a hurry, a shared server, consecutive days each depending on the previous one closing correctly, and multiple time zones with a 5 PM local cutoff.

The process — six phases, not a straight line

Requirements, visual design, AI-assisted engineering, presentation, training and production. Human verification in training and production sent work back to engineering more than once — the diagram below shows the cycle, not a line.

Diagram of the six-phase cycle: requirements, design, engineering, presentation, training, production

1. Requirements

+
-

What matters here isn't that meetings happened — it's what got decided and dropped. The points bonus stayed a manual capture on purpose, so as not to invent a rule the client hadn't settled on. The daily cutoff went through three values before landing on 5 PM local. Finding ambiguities early is the actual job of this phase.

2. Visual design

+
-

Built in Claude Design and clickable before a line of production code existed. That meant engineering never argued about visuals — a written rule (design is approved, only fix what's broken) prevented redesigning under pressure. Honest limitation: the mockup used fake data; it was a visual reference, not a behavior spec.

3. AI-assisted engineering

+
-

One commit per step, prompts as a complete file, a "report and continue" protocol, an explicit list of commands requiring one-time authorization, mandatory backups before destructive edits, raw evidence for every claim, concurrency tests run in parallel (never sequentially), and a green test suite updated in the same commit that adds a screen.

4. Presentation

+
-

The changes the client asked for were about reports and visibility — not business logic. That's a signal the requirements phase worked.

5. Training

+
-

Training material came from the system's failure modes, not a feature list — train people on what's most likely to be misread.

6. Production

+
-

First real activation with zero failures, tablet usage confirmed directly in the server logs.

The technical decisions

1. Concurrency locks live in MySQL, not in PHP

+
-

A unique phone number, an idempotency key, and a database constraint guaranteeing exactly one activation in progress system-wide. A code-level check gets raced by two near-simultaneous requests; a database UNIQUE constraint doesn't. Row locks are always acquired in the same order (inventory before balance), with retry on cross-lock — reversing that order is the textbook deadlock recipe.

2. The idempotency key is born with the logical operation

+
-

Not with the HTTP attempt. Generating it when the button is tapped means a retry after a store-WiFi timeout produces a new key — and charges twice, in exactly the scenario this defense was built for.

3. Collisions return the original success, never an error

+
-

The redemption record is written as the transaction's first statement, before balance or inventory. When the unique key collides, the response is HTTP 200 with the original redemption — an error there would make the screen retry with a fresh key, and that's where the double charge happens.

4. Operating date computed in the app with IANA time zones

+
-

Never with the database engine's own date functions — the DB server had no named time zone catalog loaded and failed silently. The real bug this avoided: with the site in UTC, the day cut over at 6 PM Mexico time instead of 5 PM.

5. Store the fact, derive the rest

+
-

An activation's status is derived from stored facts, never written as loose text. The old column that stored status as text now shows values that no longer match reality.

6. Two frozen snapshots: opening stock and the closing report

+
-

Opening stock freezes at the day's first movement, not at activation time — merchandise still being loaded in is setup, not operation. The day's report freezes at close and never recalculates — a later correction can't silently change a number the client already received as final.

7. Reversible inside the transaction, irreversible outside it

+
-

An audit row or queued email disappear cleanly on rollback; the actual email send and file writes happen outside it. A logging failure never aborts the business operation.

8. Receipt photos behind a permissioned, expiring endpoint

+
-

Outside the public folder, served with an HMAC token and expiration, so report links open with one click from a spreadsheet without a guessable URL. The redirect is attack-surface reduction, not the security boundary — the real boundary is the server's rejection at the endpoint level, written that way as a comment in the code.

9. Day open/close run lazily, with no cron jobs

+
-

They execute whenever the floor app checks the day's status — the only point in the system where a request is actually guaranteed.

10. Optimistic concurrency on inventory edits

+
-

So an administrator with the catalog screen open doesn't overwrite, with an absolute value, redemptions made on the floor in the meantime.

11. Transactional email with its own queue

+
-

A kill switch that needs no deploy, an hourly cap under the shared server's limit, and SPF/DKIM/DMARC aligned.

12. A test harness that fails on any Hooks warning

+
-

Mounts production's real files over React and a real DOM, logs in with simulated real user events, and fails the run on any React Hooks warning — not just on errors.

What broke working this way

I'm not selling this methodology as foolproof. Three incidents, one root cause underneath: the agent runs with elevated privileges, and everything it creates is born with those same privileges.

  • A configuration file ended up with the wrong owner and took down the entire site.
  • A directory created with elevated privileges blocked file writes for hours, with no visible error pointing at the cause.
  • An automated cleanup deleted work the client had already captured.

The thread running through all six phases

That the messages never lied. "Not configured" stayed distinct from "sold out" in requirements; an empty state was designed so it wouldn't read as broken; every piece of copy that described a condition wrong had a real bug behind it in engineering; training taught exactly that. Same standard, four different moments — the most transferable idea in the whole project.

Results, and what was never verified

54

scheduled activations

139

stores

19

products (up from 14, two days before the event)

1,026

inventory rows

10

time zones supported, 2 in real use

50+

files across three layers, split from one 1,858-line file

4

consecutive days chained by the single-active-activation constraint

10 / 0

concurrent requests in the concurrency test — one wins, 0 server errors

Not cited: customers served, revenue, conversion rate — not verified.

And honestly: never tested holding a tablet under real store lighting with real fingers in a hurry; email delivery to any specific inbox provider was never verified; and the customer's email is an optional field — if the operator doesn't ask, that customer gets nothing.

Evidence from the live floor app and admin panel

Illustrative stock photos stand in below — every real screenshot of this system shows either the client's logo or a real customer's data, and this case study runs with neither.

Illustrative photo of a staff member operating a point-of-sale terminal, representing the operator login step

Operator login on the floor app (illustrative photo).

Illustrative photo of a customer service counter, representing the customer registration step

Customer registration — end-to-end flow, point C (illustrative photo).

Illustrative photo of a successful point-of-sale transaction, representing a completed redemption

Successful redemption — idempotency in practice, point 3 (illustrative photo).

Illustrative photo of an analytics dashboard, representing the audit log and report screen

Frozen report and full audit log, point 6 (illustrative photo).

Illustrative photo of an open planner calendar, representing the multi-store activation schedule

Multi-store, multi-day activation schedule (illustrative photo).

Illustrative photo of retail shelving, representing the editable product catalog

Catalog with optimistic-concurrency editing, point 10 (illustrative photo).

These are stock photos standing in for real screenshots, not captures of the actual system — every real screenshot reviewed showed the client's logo baked into the UI, a real customer's name and phone number, or a real server IP, so none could be published as-is.

Short version (portfolio card)

A real-money points-redemption system for 139 stores across 54 scheduled activations: database-level concurrency locks, an idempotency key tied to the logical operation, and IANA time zones computed in the application.

Resume / LinkedIn bullets

  • Designed the concurrency model for a real-money points-redemption system using database-level UNIQUE constraints, verified with a 10-concurrent-request test: one wins, 0 server errors.
  • Fixed a live double-charge risk by moving idempotency-key generation from the HTTP attempt to the logical operation.
  • Scaled a catalog from 14 to 19 products and 139 stores across 54 activations over 4 consecutive days without breaking the single-active-activation constraint.
I work with national and international clients. Rates in USD and MXN.

Have a project that needs an engineer who delivers?

Professional contact:

Mexico City

Mexico City, Mexico Available immediately

Availability

Remote and on-site projects MXN · USD

© 2026 Eng. Samuel Torres. Applied Engineering.

Versión en español