Regulatory compliance SaaS
A multi-tenant platform for complying with Chile's extended producer responsibility law, with bulk uploads validated against domain rules. I solved the bulk upload deadlocks, which made it possible to process more than 200,000 records per upload.
- Type
- Work
- My role
- Backend and frontend development
- Year
- 2025
- Status
- In production
What the system does
Companies bound by Chile’s extended producer responsibility law must declare and organize regulated information. They do it by uploading very large CSV and Excel files to the platform.
Every incoming record is validated against strict domain rules, so processing it inside a web request isn’t viable. It is also data from many companies in a single system, and each one must see only its own.
What was given and what I did
Already built was the product, with its domain model and its multi-tenant structure.
I did:
- the fix for the bulk upload deadlocks;
- Laravel APIs with asynchronous processing on Redis queues;
- single sign-on with Auth0, from scratch;
- Vue dashboards with ECharts, cached in Redis;
- unit, integration and E2E tests with Playwright, to sustain the team’s goal of over 80% coverage.
The challenge: deadlocks in bulk uploads
Large uploads failed because MySQL aborted transactions on deadlock. Three causes added up.
- Several queue workers wrote to the same tables in parallel.
- Transactions were long and held locks for a long time.
- Processes took locks in different orders.
I solved it with four changes.
- Smaller batches. The upload is split into batches with short transactions.
- Fixed write order. Every process writes in the same order, so locks don’t cross.
- Retry on deadlock. If the database aborts a transaction, it’s retried automatically.
- UUIDs instead of sequential ids. MySQL locks auto-increment id generation, and with many parallel inserts that lock became a bottleneck.
Results
- Bulk uploads went on to process more than 200,000 records per upload.
- Corporate clients sign in with single sign-on, as their security standards required.
- The system is in production.