Delivered remotely for a business based in Lisbon, Portugal. Names withheld by agreement.
Project Overview
Retailers expanding across physical stores and digital storefronts frequently bolt together disconnected loyalty plugins—an online discount script here, a separate POS phone-number lookup there. Customers immediately feel the seams when points earned online vanish at the cash register, while finance teams inherit un-auditable points balances that distort quarterly liability reporting.
Built for an omnichannel retail and hospitality network in Lisbon, we engineered a customer loyalty platform using Laravel, Vue, and MySQL. The system unifies point accrual, tiered perks, and instant reward redemptions behind a strict double-entry accounting ledger, serving physical POS registers, web checkouts, and an interactive Vue CRM workspace from one coherent core.
Loyalty Fragmentation & Liability Risk
Scaling rewards across brick-and-mortar registers and online carts exposes four persistent architectural failures:
- Mutable balance corruption: Overwriting a single
points_balancecolumn leads to race-condition double-spends during concurrent checkouts and leaves zero trail for customer disputes. - Uncontrolled financial liability: Without strict expiration buckets and pending-return holds, unredeemed points accumulate indefinitely on the balance sheet without clear breakage accounting.
- Brittle hardcoded promotions: Launching weekend category multipliers or VIP early-access vouchers often requires developer deployments when marketing rules live in controller code.
- Slow POS register lookups: Heavy relational queries stalling at the cash register force cashiers to skip loyalty capture whenever queues build up.
Architectural Strategy
We modeled the loyalty engine on immutable double-entry accounting in MySQL 8 paired with in-memory rule evaluation in Laravel. Rather than mutating balances directly, every earn, hold, redemption burn, manual adjustment, expiration sweep, and refund clawback appends balanced debit/credit journal rows tied to source transaction IDs and expiration cohorts.
Laravel serves versioned REST APIs to store POS terminals and e-commerce checkouts while Horizon workers offload batch tier evaluations and scheduled expiry notifications. A modular Vue 3 interface gives CRM teams a visual rule builder and equips finance controllers with drill-down liability reconciliation without touching production SQL.
Core Capabilities
- Double-Entry Points & Expiration Ledger: Tracks pending, available, redeemed, expired, and clawed-back points using FIFO expiration consumption across distinct campaign cohorts.
- Composable Rules & Tier Engine: Enables marketers to configure spend thresholds, SKU/category exclusions, birthday bonuses, and dynamic tier upgrades inside Vue without code changes.
- Omnichannel POS & Checkout Redemptions: Validates QR/NFC member tokens, reserves points atomically during checkout authorization, and finalizes or releases holds upon payment confirmation.
- Return & Fraud Clawback Handling: Listens to upstream order-refund webhooks to void pending earns or record transparent debit reversals automatically.
- Segmented Member Portal: Lets shoppers inspect point histories, track progress toward their next VIP tier, and redeem digital reward vouchers across web and mobile browsers.
- Finance Liability & Breakage Exports: Generates auditable period-end summaries detailing issued, burned, and expired point liabilities by store and partner brand.
Technical Architecture
POS registers and storefront checkouts transmit signed purchase and redemption payloads to stateless Laravel API endpoints. Redis coordinates distributed member locks and caches compiled campaign rules, MySQL commits balanced ledger entries atomically, and Laravel Horizon executes downstream tier promotions, Meilisearch index syncs, and member notifications.
Flow: Physical POS & E-Commerce Checkout → Laravel API Gateway + Redis Idempotency Lock → In-Memory PHP Rule Evaluator → MySQL Double-Entry Ledger & Expiration Buckets → Laravel Horizon Workers → Meilisearch & Notification Dispatch → Vue CRM & Member Portal
Separating fast synchronous point quotes and two-phase redemptions from asynchronous tier recalculations keeps cash-register checkout latency predictable even during weekend promotional spikes.
Technology Stack
| Category | Technology detail |
|---|---|
| Merchant & Member UI | Vue 3 and TypeScript powering CRM campaign builders, finance liability reports, and member reward portals |
| Core Loyalty API | Laravel 11 and PHP 8.4 serving POS redemption endpoints, e-commerce webhooks, and rule evaluation |
| Double-Entry Ledger | MySQL 8 persisting immutable credit/debit point journals, expiration buckets, and tier history |
| Async Campaign Engine | Laravel Horizon processing bulk tier recalculations, birthday grants, and expiry notices |
| Balance & Lock Cache | Redis enforcing checkout idempotency keys, atomic redemption locks, and hot balance reads |
| Member Search | Meilisearch enabling instant phone, email, and loyalty-card lookups at busy store POS registers |
| POS & Storefront SDKs | Signed REST webhooks and QR/NFC wallet passes connecting physical cash registers with online checkouts |
| Audit & Export Bus | Scheduled accounting exports breaking down earned, redeemed, and expired points liability for finance teams |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Summing millions of ledger rows on every balance inquiry slows checkout endpoints | Maintained a transactionally updated balance cache column synchronized inside the same MySQL commit as journal entries, periodically verified against full ledger sums. |
| Expiring points cleanly across millions of members risks long nightly table locks | Tracked remaining unspent balances per credit bucket and processed Horizon expiration sweeps in cursor-chunked batches with FIFO burn tracking, trading slightly richer write logic for zero lock contention. |
| Allowing freeform promotional scripting inside CRM UIs introduces security and performance risks | Restricted marketers to a declarative JSON condition/action AST evaluated safely by pure PHP classes, balancing flexibility against deterministic safety. |
| POS checkout drops halfway through payment after points are deducted | Implemented a two-phase reserve and commit/release ledger flow with automatic Redis/Horizon TTL expiration on abandoned holds, preventing stranded customer points. |
Ledger Integrity & Fraud Prevention
Points carry real monetary value, making replay attacks, race conditions, and staff abuse primary security concerns. Every POS and e-commerce integration authenticates via scoped HMAC-signed webhooks and requires unique client-supplied idempotency keys on all earn and burn requests. Network retries during spotty store Wi-Fi replay the original response rather than crediting points twice.
Concurrent redemptions serialize through Redis distributed locks backed by MySQL SELECT ... FOR UPDATE row locks on the member's active credit buckets. Anomaly detectors running on Horizon monitor high-frequency manual adjustments by store staff, oversized same-day receipt claims, and suspicious multi-account referral loops, flagging accounts for supervisor review before high-value reward vouchers unlock.
POS Redemption Speed & Batch Campaigns
When a queue forms at a busy Lisbon checkout counter, cashiers cannot wait on multi-table SQL joins. Meilisearch resolves fuzzy customer lookups by name, phone, or card ID in milliseconds, while Redis serves pre-compiled active promotion rules and current point balances directly to Laravel's calculation pipeline.
Heavy CRM operations—such as evaluating annual tier downgrades, issuing mass seasonal bonus drops, or expiring dormant balances—run exclusively through dedicated Laravel Horizon supervisor queues with configurable throughput limits so batch marketing jobs never starve live POS traffic.
Operational Outcomes
Consolidating fragmented store and web rewards onto an auditable Laravel and MySQL ledger transformed both customer engagement and financial governance:
- Unified omnichannel balances: Shoppers earn and spend points seamlessly between physical retail counters and online carts with instant balance synchronization.
- Audit-grade accounting clarity: Double-entry MySQL journals and FIFO expiration tracking give finance teams clear visibility into active reward liabilities and monthly breakage.
- Zero-deployment campaign agility: Marketing teams configure seasonal multipliers, VIP perks, and category exclusions directly in Vue without waiting on engineering releases.
- Resilient checkout reliability: Two-phase point holds and idempotent POS endpoints protect customer balances even when store connectivity drops mid-transaction.