SShortSingh.
Back to feed

Zero-Drift Cashback Wallet Design Using PostgreSQL Ledger RPCs and Row Level Security

0
·5 views

A developer describes how the Vietnamese cashback platform Hoàn Tiền (nhanhoantien.vn), which serves shoppers on Shopee, TikTok Shop, Lazada, and Tiki, avoided common money-handling bugs. A simple mutable balance column risks double-spending during concurrent withdrawals, duplicate or out-of-order affiliate webhooks, floating-point rounding errors, and no audit trail. The fix routes every monetary change through SECURITY DEFINER PostgreSQL functions that append to an insert-only transactions table, with row locking for withdrawals. Currency is stored as integer VND across separate pending, payable, and paid totals, and Row Level Security scopes each user's access. The author reports that testing a database invariant that totals match transaction sums eliminated a whole class of financial bugs before launch.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

LVD Architecture Proposes Enforced Layering to Replace Traditional Three-Tier Designs

A DEV Community article contrasts the traditional three-tier architecture, which divides systems into presentation, business-logic and data-access tiers, with the LVD layered approach. The author argues that tiers often accumulate upward dependencies and mix stable schemas with fast-changing logic, causing volatile code to drag stable code along. LVD addresses this by allowing dependencies to run only from higher layers to lower ones, with compliance checked by tooling such as lvd-lint. The piece also outlines a five-phase migration path, from extracting schemas and utilities to isolating resources and splitting the presentation tier, with each step leaving a deployable system.

0
ProgrammingDEV Community ·

LVD and Domain-Driven Design Answer Different Questions and Work Together

The article argues that LVD and domain-driven design are not rivals but address separate concerns. DDD, from Eric Evans, centres on the domain model and helps teams identify concepts, bounded contexts and aggregates. LVD instead governs how implementation is arranged so that components changing at different rates stay decoupled. Using a library-lending example, the author maps DDD elements such as entities, domain services and domain events onto LVD's layers by volatility. The piece recommends using DDD's strategic patterns to find contexts, then applying LVD layering inside each one with ubiquitous-language names.

0
ProgrammingDEV Community ·

Kubernetes Architecture for Security-Critical Workloads: Ownership, Guardrails and Recovery

The article argues that running Kubernetes for security-critical workloads depends less on technical demos than on clear ownership, auditable decisions, and tested recovery. It recommends treating the platform as an owned control system, defining consumers, support boundaries, and recovery objectives before choosing implementations. Teams should track metrics such as saturation, scheduling latency, error-budget burn, reconciliation failures, and recovery time, and enforce tested admission policies and workload identity through a narrow, automatically verifiable contract. The piece favours a small mandatory safety core with replaceable components, and warns that expiring exceptions and unvalidated reference architectures lead to hidden risk. It also notes that stronger validation, telemetry, and isolation carry real costs that must be weighed against blast radius and recovery expense.

0
ProgrammingDEV Community ·

How Part-Time Developers Can Calculate Their Prorated Holiday Pay

A payslip showing 4.8 hours of holiday pay looked like an error, but it reflects a standard calculation. Full-time employees typically receive about 11 paid holidays of 8 hours each, a pool of 88 hours a year. A part-timer working 24 hours weekly gets a prorated share of 52.8 hours, or 4.8 hours per holiday, worth about $105.60 at $22 an hour. Employers differ in how they round these amounts and in how mid-year hires are prorated by months worked versus calendar holidays. Paid holiday hours also do not count toward the 40-hour overtime threshold under FLSA rules.