
In cross-border logistics, speed isn’t just about how fast a truck moves from Kuala Lumpur to Singapore. It’s about how fast your database can handle the metadata of that movement.
Sevendyne staffed a remote Laravel engineering pod that took over the engineering for the TLMS (Niaga Prestasi) platform: a system managing complex Malaysia-Singapore logistics operations: we inherited a high-stakes performance wall. During peak freight hours, as hundreds of drivers performed shipment scans and warehouse managers updated manifests, the system would seize. The culprit wasn’t the server’s CPU or RAM. It was MySQL distributed deadlocks.
This is the technical breakdown of how Sevendyne dismantled a synchronous bottleneck and replaced it with an asynchronous queue architecture capable of processing thousands of multi-point shipments daily with zero deadlock errors.
The Engineering Problem: The Synchronous Bottleneck
The original TLMS architecture relied on a traditional synchronous REST API. When a field agent scanned a shipment via the mobile app, the request would hit a Laravel controller that performed a heavy chain of operations:
- Update the
shipmentstable. - Recalculate status for multiple
legs(transport segments). - Trigger billing hooks in the
chargestable. - Sync status propagation across the core system.
Under low load, this worked. But logistics doesn’t stay under low load. At peak hours, multiple workers and API threads would attempt to update the same shipment or related legs simultaneously. Because these updates happened in a single HTTP request, MySQL transactions were held open for seconds.
Worker A would lock a Shipment Row and wait for a Leg Row. Worker B would lock that same Leg Row and wait for the Shipment Row.
Result: A classic circular dependency. MySQL would detect the deadlock, kill one transaction, and the mobile client would receive a 500 error. Packets were dropped, sync backlogs grew, and the field-to-core sync became unreliable.

The Solution: Moving to “202 Accepted”
Sevendyne’s first move was to decouple the API response from the business logic execution. We implemented an asynchronous edge pattern. Instead of the API waiting for the entire database chain to complete, it now validates the request, enqueues a job, and immediately returns a 202 Accepted status.
This shift transformed the system’s responsiveness. We utilized Laravel Queue Workers backed by Redis to handle the heavy lifting. By moving to a queue-based architecture, we gained the ability to throttle throughput, retry failed jobs automatically, and: most importantly: control the order of operations.
Idempotent Job Keys
To prevent duplicate processing (a common side effect of distributed workers), we implemented idempotent job keys per Shipment ID. If a driver scanned a QR code twice in rapid succession, the second job would be discarded at the queue level if a job with the same key was already pending.
The Deadlock Fix: Ordered Lock Acquisition
Switching to queues doesn’t solve deadlocks by itself; it just moves them from the API thread to the background worker. To solve the root cause, Sevendyne enforced a strict ordering discipline for database interactions.
The rule we established: Ordered Lock Acquisition.
We refactored every worker to acquire locks in the exact same sequence across the entire codebase:
shipmentslegscharges
By ensuring that every transaction always requested the shipments lock before the legs lock, we mathematically eliminated the possibility of a circular dependency.

Code Shape: Implementation in Laravel
Here is a representative look at how Sevendyne implemented the lockForUpdate() pattern within the worker logic to ensure atomicity and prevent race conditions.
// ShipmentScanController.php public function update(Request $request, $shipmentId) { // Validate request...// Dispatch to queue with a unique tracking key ProcessShipmentUpdate::dispatch($shipmentId, $request->all()) ->onQueue('logistics-high'); return response()->json(['status' => 'Accepted'], 202); } // ProcessShipmentUpdate.php (The Worker)
public function handle()
{
DB::transaction(function () {
// 1. Lock the Shipment first
$shipment = Shipment::where('id', $this->shipmentId)
->lockForUpdate()
->firstOrFail(); // 2. Perform logic and update Legs $shipment->legs()->each(function ($leg) { $leg->update(['status' => 'in_transit']); }); // 3. Finalize Charges $shipment->calculateCharges(); $shipment->save(); }, 3); // 3 attempts for deadlock retries}
Production Metrics and Real-World Results
After deploying the refactored TLMS architecture, Sevendyne monitored the system over a 90-day peak freight cycle.
The results were binary:
- 100% Reduction in MySQL Deadlocks: The “Deadlock found when trying to get lock” errors vanished from our Sentry logs completely.
- Zero Dropped Packets: Even during high-concurrency periods where thousands of multi-point shipments were active, the mobile/desktop sync clients remained 100% consistent.
The TLMS platform now seamlessly handles orders, warehouse management, dispatch, cross-border freight, and automated invoicing across the Malaysia-Singapore corridor.
Engineering Takeaways
At scale, the difference between a brittle system and a reliable one comes down to the order in which you acquire locks.
Sevendyne’s Approach: Remote Pods, Full Ownership
This project is a real example of how Sevendyne staffs remote engineering pods that take ownership of complex technical challenges. Our Laravel pod operated as a dedicated extension of the client’s team — handling architecture, implementation, and production monitoring end-to-end.
Sevendyne’s remote staffing model is built on flexible fee bands: 5% for freelance, 10% for EOR, and 15% for Kochi office-based teams. All code is delivered with 100% IP transfer (Work for Hire) — the source code, architectural blueprints, and deployment scripts belong entirely to the client.
Build your own remote engineering pod.
Sevendyne staffs, trains, and manages dedicated engineering teams across Laravel, Python, C++/Qt, and more. No overhead of setting up an India entity — just the right talent, managed for you.
👉 Hire Talent →
For more case studies like this, visit our Case Studies page. For pricing details, see our Pricing page.
Leave a comment