All posts

What it takes to run AI on 300,000 photos at home

The first version of my local AI photo library worked in a week. Making it fast and safe on a real library of over 300,000 photos took two more months. Here is what that took, and what broke along the way.

The scale slide: "Built for the library you actually have." An API process and a worker process share a task queue table, with separate CPU, GPU and Ollama pools.

Part 2 of 3 in a series on building Local Photos AI. Part 1: why I built it. Part 3: how I lead my AI coding partner.

In the first post I described Local Photos AI, the private photo library I built for my family’s 300,000+ photos, with all of its AI running at home. The first working version took about a week.

It worked beautifully on a few hundred test photos. On the real library, it fell over. Pages took seconds to load, scans ran for days, and one bug made the app rediscover photos it had already scanned every time it started. The next two months were about one thing: making it fast and safe at the scale of a real family library.

Most of the lessons are the ones I learned running cloud services, applied to a single computer at home.

Keep the slow work away from the people waiting

The first big problem was simple to describe. When a scan ran, the whole app slowed to a crawl. Loading face recognition and running AI models in the same process that answers your clicks meant every page load waited behind the GPU.

The fix was to split the app in two:

  • The API answers requests and does nothing heavy. It hands work off and goes straight back to answering.
  • A separate worker does the hours of scanning, face detection, search indexing and captioning. It has three separate pools, for CPU, GPU and the caption model, so a slow caption never holds up a batch of face detection.

Between them sits a queue, and the queue is just a table in the same SQLite database. No Redis, no message broker, nothing else to install on a home computer. The worker claims a task and keeps sending a heartbeat while it works. If the worker crashes halfway through, the task is put back on the queue the next time it starts, and nothing is lost.

That split now has a test guarding it, so heavy work can’t creep back into the API by accident.

Do the fast work first

A full AI pass over 300,000 photos is measured in days, not hours. Writing a caption for every photo with a local vision model takes many days of the computer’s idle time on its own. Nobody wants to wait that long to search.

So the work is ordered by what you notice first:

  1. Quick scan. Thumbnails, search indexing and faces come first. New photos are searchable within an hour.
  2. Captions later. A fast captioning model runs next. A slower, better model upgrades the captions later, only while the computer is idle, and backs off the moment you start using it.
  3. One question, not four. Asking the caption model for the caption, tags, scene and activity in one combined prompt cut the number of model calls by about four. Together with running several at once, indexing became six to eight times faster.

Make the screen do less

The other half of speed is what the browser does. A grid of 300,000 photos can’t put 300,000 thumbnails on the page, so only the rows on screen exist at any moment. Every list the app returns is paginated, with no exceptions.

Every request is timed, and anything slower than two seconds is logged as slow. Most of the performance work started with those logs, not with a guess.

Have the answer waiting

Some pages are expensive no matter how well the queries are written. The statistics page summarizes every photo in the library. The People page groups hundreds of thousands of faces. The map plots every photo with a location. Calculating those on demand meant waiting, so the app calculates them ahead of time and keeps the answers ready:

  • Warmed in the background. The worker recalculates the statistics, people, face groups and map after new photos are indexed, so opening a page reads an answer that’s already there.
  • Only when something changed. Each cache tracks whether its underlying data has changed. If nothing has, it isn’t recalculated, and a busy indexing run triggers one refresh at the end instead of dozens along the way.
  • Kept across restarts. The caches are saved in the database, so after a restart they load instantly instead of being recalculated from scratch.
  • Fast first, detail second. The statistics page shows a quick overview immediately, then fills in the detailed charts as they arrive.
  • Honest when cold. If a cache isn’t ready yet, the page says “Computing face clusters…” and checks back, rather than timing out or claiming there are no faces.

Face recognition gets its own in-memory cache: the average face of each named person. Rebuilding it after a change takes about 30 seconds for more than 200,000 labeled faces. After that, matching a new face against everyone is effectively instant.

Caches are also where bugs hide, so the Settings page shows each one as fresh, out of date or empty, with a button to refresh it. When something looks wrong, the first question is answered at a glance.

Use whatever hardware is there

People’s computers are all different, so the app doesn’t ask which graphics card to use. At startup it checks what the machine has: NVIDIA, AMD or Intel graphics, an AI accelerator chip, or nothing at all. It picks the best option and sizes its batches to fit about 70% of the free graphics memory.

The hardware slide: cards for NVIDIA CUDA, DirectML for AMD, Intel and Qualcomm, OpenVINO for Intel, AMD XDNA, splitting work across two cards, and CPU only.

With no graphics card at all, it still works. It’s slower, not broken. And a single corrupt file can’t stall a scan: each photo gets two minutes and each batch five, then the scan moves on without it.

Never lose a photo

Speed was the visible problem. The scarier one was safety. A photo library that loses photos is worse than no photo library, so the most important rule in the project is that the app never writes to your photo folders. Edits are saved as copies, and “delete” only hides a photo in the app.

That still left a quieter risk: the app’s own database deciding that photos were gone. Unplug the external drive that holds 300,000 photos, and a naive scan concludes you deleted all of them. So before the app removes anything from its database, it has to pass two checks:

  • Is any photo folder reachable at all? If not, it does nothing.
  • Are more than 10% of photos suddenly missing? If so, it stops and warns you. That’s an unplugged drive, not a cleanup.

The safety net slide: a decision tree that does nothing if no photo folder is reachable, aborts if more than 10% of records are missing, and otherwise hides the photo while keeping its data so it can be restored if the file comes back with the same SHA-256 fingerprint.

Two bugs taught me the rest.

The photos that were new every morning. Photos hidden from the app, but still on disk, were treated as “new” on every startup and scanned again, every time. The fix was to compare the disk with the database including hidden photos, and to check that a file is really missing before hiding it.

Two photos with the same name. Phones name photos after the second they were taken, so the same file name turns up again and again across years of backups. If the app matched a moved photo by name and size alone, it could attach one photo’s faces and captions to another. Now a moved photo is only reconnected if its contents match exactly, using a SHA-256 fingerprint of the file.

The database is also backed up every night, checked for corruption before the backup is accepted, and the last five are kept.

Old lessons, new speed

None of this is new. Separate the fast path from the slow path. Measure before you optimize. Assume the disk will disappear at the worst moment, and design so that nothing irreversible happens when it does. Every one of these lessons came from running services at cloud scale, and every one of them applied just as much to a single computer at home.

What was new was how quickly I could act on them. With Claude doing the coding, I could spot a problem in the logs, try a fix, measure it and move on far faster than I ever could alone. The next post is about how I worked with it to get there.

Thoughts or questions? Join the discussion on LinkedIn