MVC Decimal — Fractional Voucher Values
Added decimal-precision support for voucher values in the merchant voucher platform — a small, well-scoped change delivered efficiently by reusing existing design.
- Role
- Backend Engineer (Merchant Voucher)
- Timeline
- 2023
- Team
- 2
- Domain
- E-Commerce / Promotions
- Stack
- 8 tech
- Status
- Live
Overview
MVC Decimal was a small, well-scoped enhancement to the merchant voucher platform to support fractional (decimal) voucher values — for example, discount amounts that are not whole numbers. I led the design, development, and rollout, and delivered it with minimal effort by leveraging the existing voucher domain model and calculation paths rather than introducing a new subsystem.
Gallery
A backend has no screens, so its "UI" is the operational surface: the voucher API contract, the calculation flow, and monitoring dashboards.
Problem & Solution
Voucher values were previously handled as whole-number amounts, which was fine for most historical cases but limited how merchants could express discounts and how the platform could align with currency and calculation requirements that need sub-unit precision. Extending this had to be done carefully: the voucher platform is on the hot path for redemption, so any change to the value type risks rounding drift, subtle bugs, and contract breakage.
I extended the voucher value handling to be decimal-safe across the creation, storage, and redemption paths, keeping the existing API contract stable. The change reused the current voucher schema and calculation helpers, added a single, explicit rounding policy at the redemption boundary, and preserved backward compatibility for callers that still submit whole-number values. Because the scope was intentionally narrow, most of the work was in choosing the right representation, validating edge cases (currency scale, zero and boundary values, rounding direction), and adding focused tests around the calculation path.
Workflow
Three actors interact with the service; the diagrams are written in English to stay consistent across both languages.
Architecture
The merchant voucher service continues to own voucher configuration and value resolution. Values are stored in a decimal-safe form in Managed RDS, cached in Redis for hot lookups, and resolved for the order service via the existing RPC contract. Redemption applies the rounding policy at the boundary so downstream consumers always see a well-defined, rounded discount amount. Prometheus/Grafana covers issuance and redemption health.
Features
- Voucher creation with fractional value input
- Consistent decimal display in merchant-facing responses
- Decimal-safe voucher value persistence
- Rounding policy applied consistently on redemption
- Backward-compatible API contract for existing integrations
Tech Stack
Engineering Challenges
Voucher values needed to flow through creation, persistence, and redemption without losing fractional precision or introducing floating-point drift. Fix: standardize on a decimal-safe representation end-to-end and reuse the existing calculation helpers, extending them with a single rounding policy applied at the boundary.
The platform already served a large volume of live vouchers, so the rollout had to be non-disruptive. Fix: reuse the existing voucher schema and API surface, add decimal handling as an opt-in code path behind the same contract, and cover the edge cases (currency scale, rounding direction, zero values) with targeted tests before enabling it.
Outcomes
Lessons Learned
Small, well-scoped changes on a hot code path are most valuable when they reuse existing design instead of expanding surface area. Being explicit about where rounding happens — and covering the edge cases with tests before flipping the switch — is worth more than any amount of new abstraction.
Interested in working together?
Order, payment, or high-traffic event pipelines — let's talk architecture and trade-offs.