Panduan Backend & Full Stack Engineer: Arsitektur Marketplace Dua Sisi & Buku Besar Escrow

Platform marketplace dua sisi—baik yang menghubungkan pasien dengan klinik, pengirim barang dengan armada logistik, maupun klien dengan penyedia jasa—tidak boleh menyimpan saldo hanya dalam satu kolom angka saldo_dompet yang dapat diubah bebas. Pembatalan pesanan konkuren, pengembalian dana parsial, potongan komisi platform, dan pencairan dana ke mitra membutuhkan buku besar akuntansi pencatatan ganda (double-entry ledger) yang imutabel di PostgreSQL. Sebagai Senior Backend Engineer dan Full Stack Engineer, berikut adalah arsitektur finansial marketplace yang saya bangun.

1. Buku Besar Escrow Double-Entry dengan Penguncian Terurut

Setiap pelepasan dana escrow mencatat baris debit dan kredit yang jumlah totalnya selalu nol, sementara penguncian baris akun (SELECT ... FOR UPDATE) dilakukan berdasarkan urutan ID menaik untuk mencegah deadlock saat terjadi transaksi bersamaan.

2. Rekonsiliasi Otomatis & Pencairan Dana Bertahap

Pemisahan antara penampungan pembayaran pelanggan dan pencairan hasil ke mitra menjamin keamanan dana hingga layanan terverifikasi selesai.

3. Bermitra dengan Senior Backend & Full Stack Engineer

Jelajahi Panduan Utama Backend Engineer, baca Panduan Integrasi Payment Gateway, atau pesan Sprint Arsitektur Marketplace 1 Hari.

Implementasi Kode Produksi & Konfigurasi Teknis

Berikut adalah implementasi kode produksi lengkap dan konfigurasi teknis untuk arsitektur Panduan Backend & Full Stack Engineer: Arsitektur Marketplace Dua Sisi & Buku Besar Escrow:

from decimal import Decimal
from django.db import transaction
from apps.ledger.models import LedgerAccount, JournalEntry, JournalLine

def record_escrow_release(
    escrow_account_id: int,
    vendor_account_id: int,
    platform_fee_account_id: int,
    gross_amount: Decimal,
    fee_amount: Decimal,
    idempotency_key: str,
) -> JournalEntry:
    net_vendor_amount = gross_amount - fee_amount
    if net_vendor_amount < Decimal("0.00"):
        raise ValueError("Fee cannot exceed gross escrow amount.")

    ordered_ids = sorted({escrow_account_id, vendor_account_id, platform_fee_account_id})
    with transaction.atomic():
        # Lock accounts in deterministic ascending ID order to prevent deadlocks
        locked = {
            acc.id: acc
            for acc in LedgerAccount.objects.select_for_update().filter(id__in=ordered_ids).order_by("id")
        }
        entry, created = JournalEntry.objects.get_or_create(
            idempotency_key=idempotency_key,
            defaults={"description": "Escrow release and platform commission split"},
        )
        if not created:
            return entry

        JournalLine.objects.bulk_create([
            JournalLine(entry=entry, account=locked[escrow_account_id], amount=-gross_amount),
            JournalLine(entry=entry, account=locked[vendor_account_id], amount=net_vendor_amount),
            JournalLine(entry=entry, account=locked[platform_fee_account_id], amount=fee_amount),
        ])
        return entry

Checklist Arsitektur Produksi (Backend Engineer)

Dalam menerapkan solusi Panduan Backend & Full Stack Engineer: Arsitektur Marketplace Dua Sisi & Buku Besar Escrow (Backend Engineer, Full Stack Engineer, FinTech, PostgreSQL, Marketplace, Python) pada lingkungan produksi berskala enterprise sebagai Backend Engineer, pastikan standar rekayasa berikut terpenuhi:


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs