Henry Carrasco

MercadoMAX

A microservice platform for wholesale markets that follows the goods from the supplier’s dispatch note to the sale at the stall.

Year
2026
My role
System design and full development: database, backend and frontend
Team
solo
Sector
Wholesale produce markets
  • C#
  • .NET
  • Angular
  • SQL Server
  • Dapper
  • Docker
Detail of a multi-destination dispatch note: header with supplier, carrier and truck, the vehicle load bar, and the lines grouped by stall and hall

The problem

What was wrong

In a wholesale market the same load passes through five pairs of hands — supplier, carrier, receiving clerk, stevedore and trader — and each one keeps their own notebook. Nobody has the full picture, so when a truck arrives eight crates short there is no shared record of what left: the shortfall gets argued over instead of established, and the debt to the supplier is settled from memory. The data existed at every link; what did not exist was a single shared one.

The constraints

  • A single developer. Any design that requires coordinating transactions across separate databases costs weeks I do not have, and it is the constraint that shaped the most decisions.
  • The flow crosses domains at every step: the dispatch note feeds receiving, which moves inventory, which generates the sale and the debt. There is no natural boundary where consistency can wait.
  • The business operations are queries with several joins and writes that have to balance in the same round trip, not simple single-table reads.
  • The system has to run entirely on a development machine so it can be tested end to end without infrastructure.

What I built

The solution

  • Seven microservices on .NET 10 — auth, master data, dispatch notes, transport, receiving, trader and finance — each with its own schema inside a single SQL Server database, behind an Ocelot gateway with rate limiting and health checks.
  • The data layer on Dapper against 169 stored procedures: business logic lives in the database and C# invokes it and translates the result.
  • JWT authentication with refresh tokens and a token version — so sessions can be invalidated on password change — and authorization through dynamic policies: 40 permissions shaped as “Module:Action” across 9 modules and 6 roles.
  • The multi-destination dispatch note, which is the heart of the model: one truck, several stalls, lines by product, grade and logistics unit, with load checked against the vehicle’s real capacity.
  • The whole chain behind the note: receiving with shortfall recording, trader confirmation that moves inventory, sale, payable and carrier settlement.
  • The frontend on Angular 21 with standalone components and signals, no UI library, internationalisation through Transloco, a dashboard per role and export to Excel and PDF.

Seeing it work

Screenshots

How I did it

My part and my decisions

Separating what I designed from what I implemented does not take anything away: it is what lets you tell whether I can carry a design or only execute one.

01

What was mine

What I designed

The entire data model — 32 tables and the 169 operations that touch them — the split into seven services and where each boundary falls, the “Module:Action” permission scheme with its dynamic policies, the multi-destination dispatch note contract, and the phased migration plan towards my shared framework.

What I implemented

All three layers: the stored procedures, 77 C# files and around 8,100 lines across the seven services, the gateway and the shared library, with 151 endpoints; and 83 Angular components with roughly 22,000 lines of TypeScript, templates and styles. Plus the compose file that brings the whole environment up.

Who I worked with

A personal project, from end to end. The only piece that did not start here is my own shared framework — error middleware, response contracts, security, generic table and form — which I wrote separately and which this project was the first to integrate: MercadoMAX was the test of whether that was actually useful outside the drawer I wrote it in.

What I learned here

Where to really put the boundary between services, and that the honest answer is sometimes “higher than the textbook says” when the constraint is who will maintain it. Also dynamic authorization policy providers, which turn forty permissions into zero hand-written attributes. And the one that has served me most: writing the phased migration plan before touching code is what let me stop at Phase 1 with everything still compiling.

02

Technical decisions

One database, one schema per service

The textbook asks for a database per microservice. I ruled it out deliberately: working alone, that would have forced me to solve distributed transactions for a flow that crosses domains at every step. With a schema per service I keep ownership separated and queries remain a single transaction. The price is real and I accept it: the seven services share one physical point of failure, so this is a well-divided monolith rather than microservices in the strict sense — and I would rather say so myself than have the reader discover it.

Logic in stored procedures, not in C#

The obvious alternative was EF Core with the rules in the services. I chose 169 stored procedures with Dapper instead: in this domain the operations are queries with several joins and writes that must balance in the same round trip, and hand-written SQL beats a generated query. The trade-off is that the contract lives in the database and not in the repository: you test it with the database in front of you, and the compiler will not refactor it for you.

What I would do differently: the gateway, from day one

The gateway is built and works, but the frontend still connects to the seven services on their own ports: the configuration holds seven base URLs instead of one. I brought it up once the services already existed, and that is why it ended up an optional piece rather than the single entry point. Today I would put it in the first commit and never let the client know how many services sit behind it.

03

What broke, and how I fixed it

The framework migration, deliberately stopped at Phase 1

Integrating my shared library into an already-built system touched all seven services at once, and halfway through the second one it started to show: every fix opened two more fronts and the system stopped compiling as a whole for a day. Instead of pushing on, I went back to the phased plan I had written beforehand and closed Phase 1 completely — middleware, response contracts and security — leaving the other three untouched. The system ended up compiling and running, with the debt identified and bounded instead of scattered.

How it holds up

Security, errors, performance and maintainability

What keeps a system standing after it is written. Where I have not measured it, I say so.

Security
JWT with refresh tokens and a token version, so every session of a user can be invalidated on password change without waiting for expiry. Authorization is not hand-written on each endpoint: a dynamic provider builds the policies from the 40 permissions, so adding one does not mean touching control code.
Errors
A single error middleware in the shared library: every service answers with the same contract, and a failure does not escape as a raw stack trace to the client. It is the first of the four migration phases, which is why it is already in all seven.
Performance
The heavy queries are hand-written and resolve in one round trip what an ORM would take several to do; the gateway has rate limiting and health checks. I have not measured the system under load, and I am not going to call it fast because I have not tested it with real volume.
Maintainability
Schema separation keeps table ownership clear even though the database is one. The framework’s generic table and form are declared through configuration, so a new master-data screen is a config file rather than a page written from scratch. The outstanding debt is written down: three migration phases and the generic detail screens unfinished.

Outcome

What changed

The system runs in full locally — seven services, gateway and frontend — and the complete flow works end to end: the supplier’s dispatch note reaches receiving, moves the trader’s inventory and ends in a sale and a payable. It is still in development, with the scope in plain sight: the framework migration is at Phase 1 of 4. What is already closed is the model, which is the part that is expensive to redo.