Back to blog

9/10/2026 | 2 min read

Designing Shohnaat Logistics: Double-Entry Financial Accounting & Event-Driven Courier Dispatch in PostgreSQL

How I architected an enterprise courier platform managing nationwide parcel dispatch, branch hubs, and automated rider Cash-on-Delivery (COD) reconciliation with bank-grade financial integrity.

PostgreSQLRedisBullMQNext.jsFinancial SystemsLogistics SaaS
Designing Shohnaat Logistics: Double-Entry Financial Accounting & Event-Driven Courier Dispatch in PostgreSQL

Logistics platforms are fundamentally financial systems that move physical boxes. When dealing with millions in Cash-on-Delivery (COD) collections, merchant payouts, hub return charges, and delivery rider incentives, standard database updates like `user.balance += amount` will inevitably lead to financial drift and reconciliation nightmares.

For **Shohnaat Logistics**, I built a multi-tenant enterprise architecture engineered around an immutable double-entry bookkeeping ledger and distributed event queues.

## Why Traditional CRUD Fails in Courier Logistics

In standard CRUD, if a rider marks a ৳2,500 parcel as delivered and collects cash:
- The merchant ledger must be credited ৳2,500 minus COD fee.
- The rider cash-in-hand account must be debited ৳2,500.
- The company revenue account must be credited the service charge.

If any server crash or network hiccup occurs halfway through simple balance updates, the books will fail audit.

## Implementing Immutable Double-Entry Ledger in PostgreSQL

Every single cent that moves through Shohnaat is recorded as paired debit and credit journal entries:

```sql
-- Enforcing transaction balance at the database engine level
CREATE TABLE ledger_entries (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
transaction_id UUID NOT NULL REFERENCES transactions(id),
account_id UUID NOT NULL REFERENCES accounts(id),
direction VARCHAR(6) CHECK (direction IN ('DEBIT', 'CREDIT')),
amount NUMERIC(12, 2) NOT NULL CHECK (amount > 0),
created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Constraint verification function
CREATE OR REPLACE FUNCTION verify_transaction_balance()
RETURNS TRIGGER AS $$
DECLARE
balance NUMERIC;
BEGIN
SELECT COALESCE(SUM(CASE WHEN direction = 'DEBIT' THEN amount ELSE -amount END), 0)
INTO balance
FROM ledger_entries
WHERE transaction_id = NEW.transaction_id;

IF balance != 0 THEN
RAISE EXCEPTION 'Transaction unbalanced: debits must equal credits.';
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
```

## High-Throughput Queue Processing with Redis & BullMQ

Parcels undergo frequent state transitions: `Consigned` → `Hub Received` → `In Transit` → `Out for Delivery` → `Delivered` or `Returned`.

Each scan triggers SMS dispatch to customers, merchant dashboard push updates via Server-Sent Events (SSE), and inventory tracking. Instead of executing these synchronously in HTTP route handlers, we offload all side effects to **BullMQ** running on Redis 7:

- Concurrency control per merchant ensures rate limits aren't violated.
- Automatic retry strategies with exponential backoff prevent dropped webhook notifications.
- Worker separation allows logistics scanning devices in physical warehouses to experience sub-50ms API response times.

This architecture handles peak holiday delivery rushes effortlessly without financial discrepancy.

Comments

0 replies

0/2000 characters

  • No comments yet. Be the first to share your thoughts.

About Me

Rahim Badsa is a Full Stack Web Developer from Bangladesh, specializing in MERN, Next.js, Shopify, and WordPress for practical business-focused web products.

Downloads

Contact Info

Lalmonirhat, Bangladesh

[email protected]

+880 1877-104723

FAQ

Who is Rahim Badsa?

Rahim Badsa is a Full Stack Web Developer and Shopify App Developer from Bangladesh who builds production-ready web solutions using MERN, Next.js, Shopify, and WordPress. He is also the Co-founder of Rank Fast LLC and works as a Web Developer at Trinet Digital Agency.

What kind of developer is Rahim Badsa?

Rahim Badsa (also spelled Rahim Badsa, Rahim Badsha, or Rohim Badsa) is a Bangladeshi full stack web developer specializing in MERN stack, Next.js, Shopify, and WordPress development. He has delivered 100+ projects including SaaS dashboards, Shopify custom apps, WooCommerce stores, and SEO-optimized business websites.

What technologies does Rahim Badsa use?

Rahim Badsa works mainly with the MERN stack (MongoDB, Express, React, Node.js), Next.js, TypeScript, Shopify Liquid, and WordPress, alongside Tailwind CSS, PostgreSQL, Prisma, Docker, and modern frontend tools. As a full stack developer, he handles both frontend UI and backend API development, database design, deployment, and technical SEO.

Is Rahim Badsa available for freelance or remote work?

Yes. Rahim Badsa is available for freelance, contract, and fully remote collaboration with clients worldwide. Whether you need a Shopify developer, MERN stack developer, Next.js developer, or WordPress developer, he can help. You can reach out through the contact section on this portfolio or via LinkedIn.

Rahim Badsa Copyright 2026. All rights reserved.