Construction Technology and Innovation

Your First Construction API Needs More Than a Cheap MVP

A site diary looks cheap to build until a foreman takes photos without signal, retries an upload, and later disputes which image belonged to which entry. My position is that a backend developer should spend the first small budget on replayable submissions and clear evidence ownership, not a polished reporting dashboard. “Doing it properly” starts there too; it does not require a large platform on day one.

The first budget should buy a trustworthy submission boundary

Consider a narrow product: a crew member records a daily site note, attaches photos, and submits it after reconnecting. The expensive mistake is treating the successful HTTP response as proof that the whole diary entry exists. A note can reach the API while its photo is still queued on the device, and a retry can create a second entry unless both operations have explicit identities.

Give each draft a client-generated event ID, a project ID, an event type, and separate observed_at and received_at timestamps. The first is what the device reports; the second is when your server accepted the event. Keep both because a device clock can be wrong and an offline note can arrive long after the work occurred. UUIDv7, specified in RFC 9562, is a reasonable event-ID format because clients can generate it offline; its timestamp component is useful for ordering hints, not proof of when work happened.

Define the server’s acknowledgment narrowly: it means the note and its attachment references are durable, not that every referenced image is present. Return a distinct state such as pending_media until each object has been checked. That distinction matters to a project manager exporting a diary: a blank thumbnail must not silently become evidence that no photo was taken.

I would not make a PDF the system of record, because a regenerated document can hide the order in which notes, corrections, and photos arrived. Store append-only events and render the PDF from them. A correction should reference the earlier event rather than overwrite it, so a user can see what changed without interpreting database backups. This is a product rule, not a claim that append-only storage makes a record legally admissible.

Treat Can a Solo Freelancer Afford Construction-Grade Software? as a budget question rather than a database specification, because a low subscription price cannot decide what a retried offline submission means. The smallest useful deliverable is one note that can be sent twice and still appears once, with its attachment state visible both times.

SQLite and one API are a sound first deployment, but only within a defined boundary

For a first project with one small team, I would start with a Python 3.11 API, a SQLite database on a persistent server volume, and object storage for photos. SQLite’s WAL mode lets readers continue while a writer commits, which is useful for a modest diary workload; it still permits only one writer at a time, so it is not a promise about future concurrency. Keep the database on a local persistent filesystem rather than assuming a network-mounted volume preserves every locking behavior you expect.

This runnable standard-library example demonstrates the core retry rule. Run it twice: the same project and event ID still produce one row. It is a sketch of the server-side write, not an authentication or media-upload implementation.

import json
import sqlite3

db = sqlite3.connect("site-events.sqlite")
db.execute("PRAGMA journal_mode=WAL")
db.execute("CREATE TABLE IF NOT EXISTS events (project TEXT, event_id TEXT, payload TEXT, PRIMARY KEY(project, event_id))")
payload = json.dumps({"kind": "photo_attached", "object_key": "photos/demo.jpg"})
with db:
    db.execute("INSERT INTO events VALUES (?, ?, ?) ON CONFLICT(project, event_id) DO NOTHING",
               ("site-a", "demo-001", payload))
row = db.execute("SELECT payload FROM events WHERE project=? AND event_id=?",
                 ("site-a", "demo-001")).fetchone()
print(json.loads(row[0]))

Production behavior needs one more branch: if a retry uses the same event ID with different content, compare a stored SHA-256 digest and return HTTP 409 Conflict. Silently ignoring that payload would make a client believe its correction was accepted. Bind the project ID to the authenticated user on the server, because accepting an arbitrary project ID from a device would let a valid user address somebody else’s records.

The offline client also needs a durable queue. IndexedDB can serve a web app, while a native mobile app can use SQLite; neither choice changes the server’s idempotency contract. Set 72 hours as an initial queue-retention value to tune against actual site connectivity, rather than assuming a browser tab stays open until an upload finishes. Show “saved on this device” separately from “accepted by server,” because those statements describe different failure boundaries.

This small deployment stops being the economical option when operating it requires workarounds for multiple writers, unreliable volume recovery, or manual attachment reconciliation. Move the event store to PostgreSQL 16 when those costs appear; do not migrate merely because PostgreSQL sounds more construction-grade. A migration should preserve event IDs and timestamp meanings, since changing either would make old and new diary exports difficult to compare.

Direct uploads win the prototype; presigned uploads win repeated field use

There are two defensible ways to receive a photo. With FastAPI-mediated upload, the device sends the file to your API, which writes it to object storage and updates the event. This wins for a small pilot because there is one authenticated endpoint and fewer client states. It costs API bandwidth, request capacity, and careful cleanup if storage succeeds but the database commit fails.

With Amazon S3 presigned PUT, the API issues a short-lived upload URL, the device sends bytes directly to S3, and the client asks the API to finalize the attachment. This wins when photos are frequent or large because the API no longer relays every byte. It costs a more complex client protocol, orphan-object cleanup, and server-side verification before “uploaded” becomes “attached.” Those operational costs are real even if a presigned URL endpoint is quick to code.

Start with mediated uploads unless a pilot shows that API transfer is the bottleneck. For that pilot, collect a measured p95 time from “user taps submit” to “note acknowledged” over at least 100 submissions; the sample count is a planned measurement, not a performance result. Record photo size and connection state beside each timing, because an aggregate latency number cannot tell you whether the API or the site connection caused the wait. Use a provisional 30-second client request timeout as a setting to adjust after those observations, while keeping the queued item for retry.

When presigned uploads become worthwhile, make finalization idempotent too. The API should issue an object key scoped to the project and event, check that the object exists, and verify its expected size and checksum before marking the attachment present. S3’s ETag is not a universal file MD5, particularly for multipart uploads, so use an explicit SHA-256 checksum instead of treating ETag as proof of identical bytes. AWS documents 5 MiB as the minimum size for each S3 multipart-upload part except the last; that vendor-published constraint matters if the client later uploads large videos in parts, but it is no reason to build multipart support for ordinary diary photos now.

Use Construction Tech Innovations Powered by Custom Software as a prompt to name the reconciliation step your custom code removes, because “custom” alone does not make a disconnected photo and note arrive together.

A proper release makes missing evidence visible instead of promising perfection

The production threshold for this product is not an elaborate architecture diagram. It is the ability to answer, for any diary export, which events the server accepted, which attachments it verified, and which items remain only on a device. Build an export preflight check that refuses to label a report complete while referenced media is pending. Offer a clearly marked partial export when work must proceed anyway, because blocking every report until a damaged phone reconnects would create a different operational problem.

Keep a small state machine: draft_on_device, note_accepted, media_pending, and complete. Do not let the client declare complete; the server must derive it from persisted events and verified objects. If an object cannot be found after a retry window, record that failure as an event rather than deleting its reference. That makes “photo missing” distinguishable from “no photo was attached.”

Instrument the boundary with OpenTelemetry traces and a Prometheus histogram such as diary_ack_seconds, but avoid putting project IDs in metric labels because one label value per project makes metric cardinality grow with customers. Count pending attachments by age and alert on the oldest unresolved item. Choose an initial 24-hour alert threshold as a value to revise with the team’s reporting cadence, not as a universal construction standard. Keep project-level detail in logs or a queryable event table, where an operator can investigate a specific record.

Test the failure sequence rather than just the happy path: accept a note, interrupt its photo upload, replay the note, upload the photo, and replay finalization. The final state should contain one accepted note and one verified attachment. Then send the same event ID with altered content and expect HTTP 409. These tests matter because the failures occur between requests; a unit test of the insert function alone cannot show whether the user sees an incomplete export.

Finally, write down who can correct an entry and how a correction appears in an export. A foreman may need to fix a description after submission, but replacing the earlier text in place would erase the distinction between a field observation and a later edit. The rule can be simple: preserve both events, identify the editor, and render the latest text with a visible correction marker.

Build the first replay before building the first dashboard

Take one real diary note format and implement its event ID, server acknowledgment, and retry behavior without photos or PDF output. Send the identical request twice, then send a changed payload under the same ID and verify the conflict. Once that boundary is reliable, add one attachment and deliberately interrupt its upload. The resulting states will tell you what the interface and the budget actually need.