A backend take-home, and the two bugs that taught me more than the task
I got a backend take-home: build a containerized service that stores, serves, and analyzes stock price data.
What it does#
A FastAPI backend with:
- a Postgres database storing time-series price data
- a REST API to ingest and retrieve it
- a moving-average crossover strategy that backtests against that data
- tests covering most of the code
- everything running in Docker, driven by a Makefile
The part worth writing up wasn’t the checklist. It was building it like it had to hold up: handling edge cases, debugging real failures, and documenting the decisions instead of leaving them implicit.
The trading logic#
Two moving averages, one short (20-day), one long (50-day). When the short crosses above the long, that’s a buy signal. When it crosses below, that’s a sell. The system scans for crossover points and computes profit and loss from the resulting trades. A simple rule, but implementing it cleanly enough to sit behind an API, and to test properly, took more care than the rule itself suggests.
Two bugs worth remembering#
Tests were bleeding into the dev database. Tests were supposed to run against an isolated SQLite database, but kept failing in ways that didn’t add up. They were quietly connecting to the dev Postgres container instead, so state from one run leaked into the next. Fixed by isolating the test database properly and clearing stale containers before each run. Lesson: verify your test environment is actually isolated, don’t assume it.
The strategy returned zero trades. A test expected a buy signal and got nothing. The strategy only counts complete trades, a buy paired with a sell, and the test data had a buy with no matching sell. The fix was rebuilding the test data to simulate a full market cycle instead of one leg of it. Lesson: test data has to reflect the exact logic under test, not an approximation of it.
Visuals#



Source#
Code, structure, and setup instructions: github.com/ryu-ryuk/inv. There’s a recorded demo in the repo too.