Santekno
Projects/MVC Decimal — Fractional Voucher Values
Tokopedia logoPart of Tokopedia · Senior Software Engineer, Promotion Team
Backend / APILive

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.

2023-mvc-decimal · main
# E-Commerce / Promotions
$ go -X POST /2023-mvc-decimal/v1/sync
→ 201 Created
{ "status": "ok" }
publish 2023-mvc-decimal.synced
Role
Backend Engineer (Merchant Voucher)
Timeline
2023
Team
2
Domain
E-Commerce / Promotions
Stack
8 tech
Status
Live
01

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.

A backend has no screens, so its "UI" is the operational surface: the voucher API contract, the calculation flow, and monitoring dashboards.

API contract — voucher value fields with decimal precision
Ops view — voucher calculation & rounding paths
Grafana — voucher issuance & redemption health
03

Problem & Solution

Problem

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.

Solution

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.

04

Workflow

Three actors interact with the service; the diagrams are written in English to stay consistent across both languages.

flowchart diagram

create voucher with fractional value

save voucher

persist decimal amount

apply voucher

resolve voucher amount

return rounded discount

Merchant

Merchant Console

Merchant Voucher Service

Managed RDS

Buyer

Order Service

Use case interaction
sequence diagram
Managed RDSRedis CacheMerchant Voucher ServiceOrder ServiceManaged RDSRedis CacheMerchant Voucher ServiceOrder Serviceresolve voucher (order amount)lookup voucher configcached decimal configcompute discount (decimal math + rounding)final discount amountpersist applied voucher
Voucher calculation sequence
05

Architecture

flowchart diagram

rpc

metrics

Merchant Console

Merchant Voucher Service

Order Service

Redis

Managed RDS

Prometheus / Grafana

System architecture
Architecture notes

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.

state diagram

decimal value parsed

persisted with precision

rounded on redemption

drafted

validated

stored

applied

Voucher value lifecycle
06

Features

Merchant
  • Voucher creation with fractional value input
  • Consistent decimal display in merchant-facing responses
System
  • Decimal-safe voucher value persistence
  • Rounding policy applied consistently on redemption
  • Backward-compatible API contract for existing integrations
07

Tech Stack

language
Go
framework
RPC framework
protocol
RPCHTTP
database
Managed RDS (relational database)
cache
Redis
observability
PrometheusGrafana
08

Engineering Challenges

01
Preserving precision across the calculation path

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.

02
Keeping the change small and low-risk

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.

09

Outcomes

reuse
existing design leveraged
decimal
voucher value precision
low-effort
efficient delivery
10

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.