Skip to main content
Back to projects

Silk

Full-tenure reliability, security invariants, PostgreSQL query performance, and mobile launches across iOS, Android, web, and API

TypeScriptPostgreSQLDrizzle ORMHonoRedisBullMQReact RouterReact NativeExpoDockerFly.io

Ownership

Software Engineer (Mobile, Web & API)

Team

New York visual-media platform (remote, contract)

Key fact

Live apps: iOS App Store & Google Play

Silk

Overview

Silk is a visual-media social platform shipping across iOS, Android, a React Router web client, a Hono/PostgreSQL API (migrated from Next.js), and background workers. Over 15 months (Sep 2025 - Present), I built the React Native app from first build through live iOS App Store and Google Play launches, closed API security and Stripe webhook lost-write bugs backed by a static CI authorization guard, built first-party mobile crash-free telemetry and Play Console release gates, moved rate limiting to Redis, merged hot-path PostgreSQL query optimizations, and sped up real-Postgres database testing. These notes document the architectural decisions and tradeoffs behind merged and shipped work while keeping internal code and customer data private.

The Challenge

Shipping one product across native iOS, Android, web, multi-instance API routes, billing webhooks, and async workers means failures cross layer boundaries. Divergent write paths drop authorization checks; claiming a webhook event before running its handler turns a transient error into a permanent lost payment update; extra database round trips multiply on every authenticated read; and slow database tests tempt teams into mocking the very layer where regressions hide.

Constraints

  • •Enforce authorization and write-path invariants structurally in CI rather than relying on code-review memory.
  • •Verify database queries and webhook/worker recovery against a real PostgreSQL instance with migrations applied.
  • •Measure mobile startup, scrolling, and crash-free rates against real hardware and canonical server sessions.
  • •Label every benchmark with its exact environment (staging vs local) and avoid claiming unmeasured production deltas.

How it works

Problem

Multiple endpoints wrote media connections independently, creating IDOR/authorization drift and allowing unaccepted collaborator rows to pass; meanwhile, claiming Stripe webhook events before handler execution caused transient failures to permanently drop Stripe retries as duplicates, and forged multipart headers bypassed per-IP rate limits.

Decision

Consolidated connection write and media-access checks onto shared access helpers backed by a static CI guard covering sanctioned connection writers (failing the build if a writer skips access checks or accepts unaccepted collaborator rows); added claim release on Stripe webhook failure so retries reprocess cleanly; and applied per-IP rate-limit ceilings to multipart requests.

Tradeoff

Adding a new sanctioned connection writer requires updating the guard's allowlist and passing the static CI check, adding friction to one-off endpoints in exchange for blocking an entire class of authorization regression.

Impact

Closed live IDOR, multipart rate-limit bypass, and Stripe webhook lost-write failure modes, with CI guarding sanctioned connection writers against authorization drift.

Problem

Per-process in-memory API rate limits reset on deploy and drifted across API instances, concurrent identical search requests duplicated embedding calls, upload deduplication had write races, and crashed BullMQ workers could strand AI-ingestion budget holds.

Decision

Moved rate limiting into shared Redis counters across instances with bounded timeouts, coalesced concurrent query-embedding requests behind bounded caches, closed upload dedup races at the boundary, and merged liveness guards so active BullMQ holds stay alive while missing or failed jobs expire cleanly.

Tradeoff

Shared Redis checks add a network hop and require explicit fail-safe timeouts; bounded caches and liveness probes add expiry invariants that must be exercised in database tests.

Impact

Consistent cross-instance rate limiting, bounded fallback memory, and recoverable AI-ingestion budget accounting across worker failures.

Problem

Hot-path authenticated reads paid two PostgreSQL protocol round trips per lookup (unnamed parse/describe then bind/execute) and issued five SQL statements across two sequential waits to enrich follow state.

Decision

Switched the hot auth lookup to a module-scoped server-side named prepared statement (Drizzle + postgres.js reusing the prepared statement on a warm connection in 1 round trip) and collapsed follow enrichment into 3 joined SQL statements in 1 sequential wait.

Tradeoff

Named prepared statements depend on session-level connection stability (production and staging use Neon's direct endpoint, not transaction-mode PgBouncer; moving to a pooler later requires prepared-statement pooler support) and need reconnect and schema-revalidation tests.

Impact

Cut hot-path auth lookup from 2 protocol round trips to 1 (-58% p75 query latency measured on staging: direct Neon session, postgres.js + Drizzle, 24 warmed alternated samples per arm; production latency not yet benchmarked) and follow enrichment from 5 SQL statements to 3 (18 baseline/candidate responses matched byte-for-byte).

Problem

The 157-file shared PostgreSQL test suite took 42.1s locally in a single serial group, slowing iteration and tempting engineers to skip or mock real-database coverage.

Decision

Split the shared DB test group round-robin across 4 parallel groups on cloned template databases, cut hub type-only schema dependencies (35 to 19) with a fail-closed hub-edge CI lint guard, and wired import-graph test selection in the merge queue (running the full DB suite post-merge on main).

Tradeoff

Import-graph test selection must fall back to the full suite whenever shared schema or scripts change, and parallel groups require strict per-group database isolation.

Impact

Cut local Postgres wall time for the 157-file shared DB suite 39% (42.1s to 25.6s, 0 failures) without mocking PostgreSQL.

Approach

1. Ship iOS and Android on real-hardware gates

Built Silk's React Native and Expo app from first build through live iOS App Store and Google Play launches, pairing ART baseline profiles, merged Android FrameMetrics diagnostics, first-party canonical-session crash-free rates, and Play Console crash/ANR release gates.

Ship iOS and Android on real-hardware gates

2. Turn security and billing bugs into structural guards

After fixing media-connection IDOR/authz flaws, multipart rate-limit bypasses, and a Stripe webhook lost-write bug, enforced shared access helpers and accepted-collaborator checks across sanctioned connection writers via a static CI guard.

3. Eliminate database round trips with verified parity

Merged changes cutting hot-path auth lookups from 2 Postgres protocol round trips to 1 via named prepared statements (tested across reconnects and schema changes against real Postgres) and collapsing follow enrichment from 5 SQL statements to 3 with byte-for-byte response checks.

4. Keep real-database verification fast

Refused to mock Postgres on query refactors; instead cut local wall time for the 157-file shared DB suite 39% (42.1s to 25.6s) with 4 parallel template-DB shards plus fail-closed import-reach selection in the merge queue.

Outcome

Silk's mobile app is live on both the iOS App Store (cx.silk.native) and Google Play (cx.silk.mobile), backed by 15 months of full-stack delivery across mobile, web, the Hono/PostgreSQL API, Redis/BullMQ workers, Docker/Fly.io deploys, and CI verification. Recent December native diagnostics and backend query optimizations are merged on main; the auth latency reduction (-58% p75) was measured on staging (direct Postgres session, 24 warmed alternated samples per arm; production not yet benchmarked), and the 39% DB test speedup (42.1s to 25.6s) was measured on local runs of the 157-file shared Postgres suite.

At a glance

iOS App Store & Google Play

Live apps

2 to 1 round trips (-58% p75 staging)

Auth query path

5 to 3 SQL statements (2 to 1 waits)

Follow enrichment

42.1s to 25.6s (-39% across 157 files)

Local Postgres suite

Learnings

  • →Structural CI guards beat prose reminders: encoding authorization and schema-hub invariants in CI stops whole classes of repeat regressions.
  • →Removing a protocol round trip or sequential SQL wait is simpler and safer to maintain than layering a cache over a chatty path.
  • →Fast local real-Postgres suites (42.1s to 25.6s) keep engineers running real database tests before pushing rather than waiting on CI.

Anti-patterns avoided

  • ×Relying on code review instead of CI guards to keep authorization checks on sanctioned write paths.
  • ×Claiming webhook idempotency keys before handler success without releasing on transient failure.
  • ×Mocking PostgreSQL drivers on query refactors instead of running real migrations.
  • ×Reporting staging or local benchmarks as production measurements.

Get in touch

Want to talk about similar work?

Next project

Margin