Skip to content
vp.Ven Petrov
WorkAI demoWritingResourcesResume / CVAboutAt a glance
← Projects & notes
Sociedades Inactivas enquiriesTechnical note · 3 min read

An enquiry should survive a failed email

A failed notification should not make someone submit the same enquiry twice. The implemented form keeps the saved request and its reference while email delivery is retried; live activation is still pending.

Ven PetrovImplemented; live activation pending

On Sociedades Inactivas, a visitor can choose an already incorporated Spanish company and ask about it, or send a general enquiry. Once they press Send, the application needs to keep their request and notify the people who will handle it.

Those two jobs can finish differently. The database might save the message while email fails. If the visitor sees only a failure and sends again, the same request can arrive twice.

I separated the stored enquiry from its notification. In the implemented flow, success means the visitor has a stored reference. Email delivery has its own state and can be retried. This behavior is tested locally; production form activation is still pending.

Follow one request when email fails

The code handles this sequence. It is an example of the failure behavior, not a report of a particular customer losing a message:

Event What the application keeps
Valid form arrives Enquiry and pending-delivery record are saved together
First email attempt fails The same enquiry remains saved; delivery stays pending
Visitor repeats the same request The original reference is returned
Same request key arrives with changed content A conflict is returned instead of silently using the old message

The pending-delivery record is an outbox: notification work stored in the database for a later attempt. The enquiry and that work are written in one transaction, so they succeed or roll back together.

One test deliberately makes the outbox insert fail. The enquiry and its rate-limit increments must roll back as well. Otherwise the database could contain a request with no notification work attached to it.

The database commits before the email attempt

  1. 01Submission keyCheck the key and payload fingerprint
  2. 02TransactionSave enquiry and delivery record together
  3. 03SMTP attemptClaim the record with a lease token
  4. 04Saved referenceReturn it even if email fails
A failed SMTP attempt leaves the saved enquiry and its pending delivery record available for retry.

Sending again should not create a different request

The browser includes a submission key. The server keeps a hash of that key and a fingerprint of the validated message content.

If the same key arrives with the same content, the server returns the original reference before charging the submission quota again. If the key is reused with different content, it returns HTTP 409. The visitor's first message is not silently substituted for an edited one.

A company selected in the form is checked against the current catalogue inside the transaction. The stored company name comes from that lookup. The browser cannot supply an arbitrary name and have it treated as a catalogue entry.

If the company has been removed or sold, the visitor can remove the selection and send a general enquiry. That leaves a way to ask a question without accepting an outdated company choice.

Saving is finished before delivery begins

After the commit, the API waits for its first email attempt. A mail error is caught while the saved reference remains available.

A retrying worker first claims the delivery record with a lease token. That temporary claim lasts 60 seconds. Other workers should leave the record alone while the lease is current. A failed attempt is rescheduled with increasing delays, capped at six hours. The final update checks that the worker still holds the matching token.

This controls who can update the pending work, but it does not promise exactly one email. A mail server might accept a message just before its response is lost. A lease might also expire during a slow send. The stored request and confirmed delivery remain separate facts.

All eleven focused tests pass using disposable databases and mocked mail. They cover storage, duplicate requests, rollback and delivery behavior. The deployment record still has the production contact route returning 503 before saving, with security and mail configuration deferred. The result here is a tested implementation, not evidence of successful live enquiries.

Project sources & checks
Local repository and code review

sociedades_inactivas_new_web: app/api/contact/route.ts, lib/db/contacts.ts, lib/contact/delivery.ts and tests/contact.test.mjs.

Focused verification

All eleven existing contact tests passed locally, using test databases and mocked delivery.

Dated deployment record

docs/PROJECT-STATE.md records the production contact route returning 503 before storage, with security configuration and mail setup deferred.

On this page
Follow one request when email failsSending again should not create a different requestSaving is finished before delivery beginsSources & checks
Next.jsTypeScriptTursoReliability

Connected to this

All writing
3D Spaces website migration · Project story

Moving 3D Spaces without moving its mailbox

Capture CRM · Project story

Save the listing now, connect the person when the details arrive

Ven PetrovSoftware engineer · Barcelona
GitHub ↗LinkedIn ↗Email ↗

Find a project or a note

18 results

Transfutur ERP · ExperienceERP for transport and logisticsAs the sole engineer, I built an ERP from zero for transport and logistics. It supported roughly €5–6 million in annual invoicing across two offices, and I kept it running for about a year.Finance evidence desk · Project storyCan an AI reviewer improve a financial explanation?A finance review needs the right explanation as well as the right numbers. I tested one AI analyst, an added reviewer and self-review on the same public report. The added review produced fewer supported answers.Financial review lab · Project storyWhat contributed to an $86 million rise in operating income?I built a financial-report explorer around a question I could check: how did seven income-statement movements add up to an $86 million increase? The same source now supports comparisons of sales, cash flow and reported versus core results.MNQ time-series research · ExperimentA time-series model that failed on later dataA model gained about $2,351 in the research simulation, then lost about $1,728 in three later windows. I followed the experiment from data acquisition and time intervals to costs, evaluation and the decision to reject it for trading.Crude-oil narrative tracker · Project storyFollowing crude-oil news without losing the market numbersI used a short personal experiment to follow global events alongside crude-oil prices and position values. The prototype calculates the numbers before asking Claude Code for an assessment and keeps a limited recent history.NQ/MNQ backtest engine · Technical noteYesterday’s short was blocking today’s trades in the simulatorWhen input stopped before the scheduled close, the strategy forgot a position but a shared counter kept counting it. Closing the old position before resetting the day restored the trade record and released the block.Small-cap edge research · Project storyWhat would make a small-cap price pattern worth testing?I built a Python and DuckDB prototype to turn trading ideas into named tests, compare their costs and revisit them in later periods. The candidates deteriorated under further checks, and the source exposed a misleading pass flag.Gadgeon Europe applications · ExperienceConnected-device dashboards and mobile apps at Gadgeon EuropeThe dashboards let people monitor energy use and control connected devices through data from several APIs. My work covered customized Ionic and Angular apps, integrations, store releases and maintenance.ctxforge · Project storyctxforge: turn “add search” into a task an agent can build“Add search” leaves decisions about data, matching and behavior unanswered. I built an editable toolkit that asks an LLM to uncover those requirements and show its assumptions before a coding agent starts.Sociedades Inactivas enquiries · Technical noteAn enquiry should survive a failed emailA failed notification should not make someone submit the same enquiry twice. The implemented form keeps the saved request and its reference while email delivery is retried; live activation is still pending.Astro local-services website · Project storyKeeping local service pages and their FAQs consistentA city page should only offer services enabled for that location. I used shared Astro templates with explicit availability rules, and one FAQ selection for both the visible page and its structured data.3D Spaces website migration · Project storyMoving 3D Spaces without moving its mailboxThe website could move to Next.js and Vercel, while email still depended on the old host. I carried over the pages, enquiry flow and analytics, then checked what the cutover had actually preserved.Capture CRM · Project storySave the listing now, connect the person when the details arriveA classified listing may arrive before its phone number or contact name. Capture CRM keeps those records separate, then lets a later capture complete the existing listing and bring contact status back to the browsing page.Product-description comparison bench · ExperimentWhere did the product description get that detail wrong?A product description can go wrong when the image is read or when the copy is written. This local bench exposes both steps, lets me switch models and records request measurements. A matched quality comparison is still unfinished.Between Us · Project storyBetween Us: keeping control of a generated filmA more emotional dialogue take still needed convincing acting and framing. I kept the alternatives, widened shots to reveal gestures and changed the workflow when its studio limited the films I wanted to make.Restaurant-service voice agent · ExperimentDesigning a restaurant-service call around the real offerThe first correction was the offer: a paid service had become a free visit in one draft. I then compared how the Spanish voice-agent prompts handled new speakers, technical limits and booking results.Vapi and Telnyx voice integration · Technical noteThe Vapi agent could speak, but it could not hear me clearlyI could hear the assistant, but it could not understand my distorted audio. Three codec tests changed the connection behavior and brought the greeting back; the caller-audio problem remains unresolved.Warloop: Echoes of Solmara · Project storyWarloop: turning generated character art into a playable prototypeGood-looking character images became tiny figures, a backwards walk and misplaced bosses in the game. I worked through the gap between generated art and playable behavior.
esc to close · Tab to move through results