Skip to content

About

Backend for 100 Photos

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

100 Photos - Backend

A friends only social media app that limits you to 100 photos per year. Each post should be treated like a top 100 of the year photo!

Client: 100-photos-app


Why 100

  • 100 is roughly two posts a week, making a weekly highlight, not a daily check-in.
  • At the end of the year you've made the top 100 photos of your year.

How the constraint actually works:

  • Each post has a column for number and year.
  • Hit 100 and you're done until January 1.
  • Deleting only refunds the slot if the post is under an hour old.
  • The year rolls over on the user's local calendar, not UTC. A timezone interceptor carries the client's zone into get_or_create_post_quota.

Features

  • 100 posts per year per account, enforced server-side with a per-user quota
  • Home feed materialized per user with fan-out on write
  • Profiles, friend requests, friends
  • Comments and ratings
  • Direct-to-bucket photo uploads via signed URLs
  • Timezone-aware year rollover on the user's local calendar

Status

Not published, no real users besides my friends. The API and client both run, and the features are essentially complete:

  • Profiles, friend requests, friends
  • Posts with the per-year quota enforced
  • Ratings and comments
  • Home feed + profile feed

What's missing:

  • Tests
  • Documentation beyond this file
  • Beta testing

Nothing has been under real usage, so undiscovered bugs are a certainty rather than a risk


Tech stack

Area Choice
Language Go 1.25
API gRPC + Protocol Buffers (buf schemas in proto/, generated in pb/)
Validation protovalidate, request validation declared in the proto
Database PostgreSQL on Neon, via pgx/v5
Auth JWT verified against a remote JWKS, refreshed in the background
Storage Google Cloud Storage, direct-to-bucket uploads via signed URLs
Async Cloud Tasks, async fan-out
Hosting Cloud Run, deployed by Cloud Build (cloudbuild.yaml)
Migrations golang-migrate, versioned migrations in sql/migrations/

Architecture

Two binaries, one Postgres, one bucket.

cmd/api - gRPC server. validation, reads, writes.

cmd/worker - plain HTTP server that only accepts Cloud Tasks deliveries, verified by OIDC token (audience and service account are both checked in production).

Photo bytes never pass through the API. Clients ask for a signed URL, upload straight to GCS, and the API promotes the object to permanent once the post is created.

The feed

home_feed is materialized per user with fan-out on write. Events (PostCreated, FriendAccepted, FriendRemoved) go onto Cloud Tasks instead of fanning out inline. home_feed_meta tracks version against target_version: a write bumps the target, the worker advances the version once it's caught up.

The repair path is blunt. If target_version > version for more than 15 minutes, or the feed hasn't been rebuilt in a week, the whole feed is deleted and rebuilt from scratch. Reads also self-heal: GetHomeFeed syncs on the first page and drops rows for posts that no longer exist.

Probably not implemented in a robust enough way to be true production ready but it was going to add a ton of complexity for what is a relatively small project.

Conventions

Services all share the same shape:

internal/<service>/
  grpc.go        transport: proto ↔ domain, no business logic
  service.go     business logic
  postgres.go    write operations in the database
  domain/        entities, repository interfaces, typed errors
  queries/       similar shape as above but for read only operations

queries/ exists so the feed can read posts, profiles and relationships without depending on their write side to prevent circular imports.


Getting started

You'll need Go 1.25+, Postgres, a GCS bucket, and the buf and migrate CLIs.

The GCS bucket is required. Auth: the server only consumes a JWKS endpoint, so any issuer that publishes one will work. Neon Auth is what I used since I already used Neon DB, Neon Auth is just a hosted Better-Auth and not really made for Mobile apps.

cp .env.example .env          # fill in DATABASE_URL, NEON_URL, GCS_BUCKET
make migrate-up               # apply migrations
make run-api                  # :8080
PORT=8081 make run-worker     # separate shell and must not share the API's port

In development the API dispatches events straight to CLOUD_TASKS_TARGET_BASE_URL instead of going through Cloud Tasks, so you can work on feed code without a queue. Point it at the worker's port.

Useful commands

make gen regenerate protobuf code
make db-backup dump schema to sql/schema.sql
make docker-api / make docker-worker build images

Deploying

Cloud Build builds both images, runs migrations, then deploys the worker before the API. The API needs the worker's URL. scripts/deploy-local.sh reproduces it from your machine; see scripts/README-deploy-local.md.


About

Backend for 100 Photos

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages