SShortSingh.
Back to feed

How one developer enforced free-plan limits inside Postgres instead of the UI

0
·65 views

A developer building a release-tracker app moved free-plan enforcement from the frontend into a PostgreSQL database trigger, arguing that UI-side checks are easily bypassed via extra tabs, stale sessions, or direct API calls. The trigger fires before each insert into the follows table, counting existing rows for the user and rejecting any attempt to exceed 10 followed technologies on the free plan. A PostgreSQL advisory lock keyed to the user ID prevents race conditions where two simultaneous inserts could both pass the count check independently. Custom SQLSTATE error codes are returned through PostgREST directly to the browser, allowing the frontend to display precise, code-driven rejection messages without parsing error strings. The author notes the trigger also blocks follows of retired technologies and is designed to accommodate future paid-plan logic in a single, authoritative location.

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 ·

RBA Questions AI Productivity Gains as Data Centre Spending Strains Economy

Reserve Bank of Australia Assistant Governor Sarah Hunter told the UBS Australasia Conference in Sydney that evidence of AI meaningfully lifting productivity or reducing employment in Australia is still limited. She noted that data centre capital spending has risen roughly tenfold in recent years, placing demand pressure on the power grid, construction sector and engineering workforce. Hunter warned this investment could fuel persistent inflation and keep interest rates high. She also flagged that shared cloud and foundation model providers create new systemic risks to financial stability.

0
ProgrammingDEV Community ·

AI Hackathons Need Scoped Budgets, Not Shared Keys or Cards

AI teams often struggle less with ideas than with a clean way to pay for experiments, and this quickly becomes a developer-experience problem. Default workarounds like shared subscriptions or shared API keys are convenient at first but create security risks, accounting confusion, and unclear ownership. The article proposes treating experimental AI budget as a temporary, bounded capability, similar to short-lived branches or limited tokens. Contributors would receive a defined credit envelope that limits spending without exposing the sponsor's full account or credentials. The author notes that prepaid credits or gift cards can support this model, though rules vary, and that such budgets should still be paired with engineering controls like server-side secrets, input validation, usage logging, and per-user limits.

0
ProgrammingDEV Community ·

Guide Explains Using One Free IPv6 /48 Across Two VPS Providers Without Renumbering

A network operator describes how to announce a single IPv6 /48 prefix from two VPS hosts in different cities so both sites can carry traffic. The article recommends setting local-preference and AS-path prepending to make one site primary and the other a backup, while keeping ROA maxLength at /48. It also covers export filters, drain and withdrawal procedures during maintenance, and choosing between anycast and DNS failover for stateless versus stateful services. The piece is written by a leasing company's representative, who discloses that the company's IP space is featured in the walkthrough.

0
ProgrammingDEV Community ·

Python script flags failing endpoints and slow requests in fictional iPhone log demo

A DEV Community tutorial shows how to build a small Python log analyzer that runs on an iPhone using only the standard library, requiring no server or network connection. The script parses simplified, fictional access-log lines, rejecting malformed entries while keeping their line numbers visible. It counts HTTP 5xx server failures, computes a 30% server-error rate across ten parsed requests, and reports a 195 ms median latency. It also ranks the slowest requests and groups failures by endpoint, with checkout showing the most errors. The author stresses that such summaries point to where to investigate rather than revealing the underlying cause.