The ROI at a Glance
- Eliminated Manual Data Entry: Saved the accounting team 20+ hours per week by fully automating the Sage 50 invoice lifecycle.
- Omnichannel Consolidation: Merged digital self-serve orders and physical field-sales operations into a single, reconciled ledger.
- Infrastructure Efficiency: Reduced the database pricing footprint by 95% using a hybrid resolution matrix, accelerating page loads to under 300ms.
- SaaS Independence: Replaced disjointed third-party apps with a self-hosted, scalable AWS monolith featuring 99.9% uptime.
1. Executive Summary: The SaaS Limit
In the world of B2B commerce, "one price fits all" is a myth. Wholesale distributors operate on complex human relationships, volume contracts, and negotiated tiers. Standard e-commerce platforms like Shopify are built for B2C retail; they assume a product has one price. A true B2B platform must understand that a single product has thousands of prices, depending entirely on who is authenticated.
My client, Dairy Farm Products, was hitting a severe operational ceiling. They were managing a high-volume distribution business using a fractured ecosystem: a legacy accounting system (Sage 50 Business Cloud) that held the ultimate financial truth, field representatives tracking physical cash payments, and administrative staff acting as "human routers"—manually double-entering web orders into spreadsheets and accounting software.
They did not need a new website. They needed an Enterprise Operations Hub.
The mandate was absolute: Architect a unified digital ecosystem where complex, customer-specific pricing resolves in milliseconds, physical field sales sync with digital self-serve orders, and every transaction flows bi-directionally into Sage 50 without a single manual keystroke.
2. The Operational Bottlenecks
While the frontend user interface needed to feel as frictionless as a modern B2C app, the backend had to resolve three severe enterprise constraints.
Constraint 1: The Combinatorial Pricing Explosion
The client required strict, customer-specific pricing. In a naïve database architecture, one might create a unique row for every product-to-customer combination.
- The Threat: If a distributor has 5,000 products and 2,000 wholesale customers, that generates 10 million records just to store baseline prices. This bloats the database, degrades query performance, and makes mass adjustments (e.g., "Increase all dairy by 5%") computationally devastating.
Constraint 2: The Legacy Integration Gap
Sage 50 is an exceptional financial system of record, but it is notoriously rigid.
- The Threat: Sage 50 does not provide native webhooks for real-time web synchronization. We could not simply "listen" for inventory or invoice changes. Furthermore, the web platform had to respect Sage as the ultimate authority on credit limits and ledgers. Without automation, the accounting staff was trapped manually reconciling digital orders against legacy software.
Constraint 3: The Omnichannel Disconnect
Wholesale isn't just digital. Sales representatives were visiting physical shops, taking orders on tablets, and collecting physical cash or past-due payments in the field.
- The Threat: Reconciling field-collected cash against online Stripe payments and matching both to the correct Sage 50 invoice was causing severe accounts receivable delays and human error.
3. The Architecture: Engineering Leverage
To solve these bottlenecks, I bypassed the temptation of trendy microservices—which would have introduced crippling network latency to our pricing calculations. Instead, I engineered a strictly typed Modular Monolith deployed on self-hosted AWS ECS (Elastic Container Service).
This provided enterprise-grade resilience without the unpredictable billing or "cold starts" of serverless platforms.
Module A: The Millisecond Pricing Matrix
To solve the "10 million records" problem, I engineered a cascading, hybrid pricing engine. Instead of a 1-to-1 mapping, the database resolves prices through a prioritized, three-tier logic gate:
- Base Price: The default retail price defined on the master product.
- Tiered Group Price: Customers are assigned to logical wholesale brackets (e.g., "Regional Distributors"). The system checks for active adjustments applied to this tier.
- Customer Override: The system checks for highly specific, negotiated contract exceptions linking a single user to a single product.
The Logic Flow: Does this user have a contract override? If yes, use it. If no, does their Wholesale Tier dictate a price? If yes, use it. If no, fallback to Base Price.
This exact architecture reduced the required data footprint by 95%. Administrators can adjust a "Tier" price once, and it instantly cascades to hundreds of associated accounts.
Module B: The Anti-Fragile Sage 50 Poller
Because Sage 50 lacks real-time webhooks, I realized that forced eventual consistency was the only robust path forward. I architected a custom synchronization layer powered by Redis and BullMQ.
Instead of blindly overwriting data, I built a background "Diff Engine."
- The worker processes run on an isolated background thread, pulling snapshots of modified records from Sage 50.
- It calculates hashes against our PostgreSQL database and updates only the records that have mutated.
- Resilience: If the Sage API throttles the connection or experiences downtime, the background job gracefully fails and utilizes an exponential backoff strategy. No data is lost; the system simply catches up when the connection is restored, turning a fragile third-party dependency into an automated, fault-tolerant pipeline.
Module C: Omnichannel Ledger Reconciliation
To unify the field reps and the digital storefront, the system relies on a central, typed schema (tRPC and Zod). When a field rep logs a physical cash payment on their portal, or a customer pays an outstanding invoice via Stripe on the self-serve app, the transaction hits the same validation layer. The Admin dashboard can instantly allocate these payments to specific open invoices, triggering the Redis queue to push the reconciled balance directly into Sage 50.
4. The Business Impact
The deployment of this bespoke operations hub fundamentally altered the leverage of the business.
- Eradication of Administrative Bloat: The bi-directional Sage 50 poller entirely eliminated the need for manual invoice and inventory entry. An order placed digitally or in the field appears in the accounting ledger within minutes, saving the operations team an estimated 20+ hours per week.
- High-Performance Stability: Despite calculating deeply complex, customer-specific pricing on every page load, optimized Prisma queries allow the B2B storefront to render in under 300ms. The containerized AWS infrastructure has maintained 99.9% uptime, processing thousands of inventory mutations silently in the background.
- Pricing Agility & Zero Errors: Billing discrepancies have been effectively neutralized. Management can execute complex seasonal pricing strategies or update vendor contracts instantly, knowing the logic will safely propagate across both the web app and the field sales portals.
By refusing to compromise on data integrity and acknowledging the true complexity of B2B workflows, we didn't just build an e-commerce site. We built an automated engine that protects margins, scales without additional administrative headcount, and powers the entire operational lifecycle of the business.
Are your highly-paid employees acting as "human routers" between your e-commerce frontend and your legacy accounting software? Let's fix your operations. Book a Technical Audit to see how much margin you can recover through targeted system automation.
