SShortSingh.
Back to feed

How to Build a Discount-Validation API That Catches Stacked-Coupon Math Errors

0
·1 views

Developers building promotional pricing engines often make a common mistake by adding percentage discounts together rather than applying them sequentially as multiplicative factors. For example, a 20% discount followed by a 10% discount yields a 28% total reduction, not 30%, because each discount applies to the already-reduced price. A more reliable approach models discounts as ordered tuples and surfaces each calculation step in the API response, while also clamping the final price to prevent negative totals when fixed-amount coupons exceed the item price. Discount order also matters once fixed-amount or BOGO coupons enter the mix, so the application layer should define and document a canonical ordering rather than leaving it to front-end teams. Rounding rules add a third layer of complexity, requiring consistent and documented behavior at intermediate steps to satisfy both auditors and floating-point precision constraints.

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 ·

Design Agentic AI Systems by Defining Constraints Before Choosing Architecture

A recurring mistake in agentic AI development is selecting tools and frameworks—such as LLMs, LangGraph, or multi-agent setups—before clearly defining product requirements. A more effective approach inverts this order: start with the desired outcome, establish constraints across four dimensions (latency, cost, failure, and evaluation), and only then choose the architecture and tools. Using an AI Incident Resolution Assistant as a case study, the author demonstrates how constraint-first thinking can replace a complex six-agent pipeline with a leaner, hybrid system that routes known incidents through deterministic workflows and reserves autonomous agents for genuinely ambiguous cases. This distinction—deploying agents only where reasoning variability exists, not simply because the technology allows it—leads to systems that are faster, cheaper, and easier to trust. The LCFE framework proposed is not a rigid template but a discipline for grounding architectural decisions in operational reality rather than technical possibility.

0
ProgrammingDEV Community ·

AI Voice Agents Face Security Risks From What They Can Do, Not Just What They Say

Security vulnerabilities in AI voice agents stem not from jailbreaking or prompt manipulation, but from the real-world actions these agents can perform, such as reading CRM data, booking appointments, and sending texts. Because the entry point is simply a phone number with no login or verification, anyone who calls can potentially trigger these actions. A developer building agents for clinics and other businesses found that tools often accept caller-supplied parameters without verifying the caller's identity, allowing strangers to access other people's records. Caller ID spoofing and shared phone numbers make phone numbers a weak form of authentication, so the developer now splits access by consequence — requiring an additional verification step like a date of birth for any sensitive data or record changes. System prompt instructions are described as useful for shaping normal behaviour but ineffective as a security control, much like client-side form validation alone cannot protect a database.

0
ProgrammingDEV Community ·

Watchdog: Open-Source Bash Tool Monitors Linux Services and Automates Recovery

Watchdog is a lightweight, open-source Bash utility designed to monitor the health of Linux services such as APIs, background workers, and database listeners. It supports HTTP, TCP, and command-based health checks, each configurable with timeout, retry count, and retry-delay settings. When a service fails all configured retries, Watchdog executes a defined remediation sequence using direct argument arrays rather than shell strings, reducing security and configuration risks. The tool is intentionally stateless and one-shot, meant to be triggered via systemd timers or cron jobs rather than running as a persistent daemon. MIT-licensed and requiring only Bash 4.3 or newer, Watchdog targets developers who want a simple, auditable, host-level recovery tool without the overhead of full observability platforms.

0
ProgrammingDEV Community ·

Blue-Green Deployment Left Idle Environment Running for 6 Weeks, Doubling AWS Costs

A software team's blue-green deployment went smoothly, but the old 'blue' environment was never decommissioned after traffic shifted to the new 'green' setup. For six weeks, all original EC2 instances, RDS nodes, and load balancers continued running at full cost while serving zero traffic. The oversight stemmed from an ownership gap — the deployment team assumed operations would tear it down, while operations assumed the reverse. The incident highlights a blind spot in blue-green strategies: the rollback window stays open indefinitely unless someone explicitly owns the shutdown decision. Experts recommend tagging old environment resources with a TTL at launch and integrating cost anomaly alerts to flag idle infrastructure past its deadline.