Backend audit and soak gate
You add a backend audit target and a 10-minute soak script that scan dependencies, lint production code, run race tests, and check goroutine recovery.
Ticket
Build a repeatable backend audit and a soak script. The audit target in backend/Makefile must run vulnerability scanning, production-code linting and race tests. The script at backend/scripts/soak.sh must run the existing browsing workload while recording goroutine and heap measurements from pprof.
The product needs these checks because a successful short test run does not prove that the service can handle sustained traffic without leaking resources. The next exercise adds per-minute order statistics for restaurant staff. Keep the same quality gates in place as the backend grows.
No test calls Go code directly in this exercise. The tests run make -n audit, read .github/workflows/backend.yml and backend/scripts/soak.sh, run bash -n on the script, and run an end-to-end burst of 150 clients against the running API while reading the goroutine count from the private pprof listener.
Acceptance criteria
- The
make -n auditoutput containsgovulncheck ./..., agolangci-lint runcommand and ago test -racecommand. - The
.github/workflows/backend.ymlworkflow mentionsgovulncheckand runs tests with-race. - The
backend/scripts/soak.shscript references bothdebug/pprof/goroutineanddebug/pprof/heap, invokesk6 run, and passesbash -n. - After a burst of 150 concurrent clients, the goroutine count returns to within 15 of its baseline within 15 seconds, using 500 ms polling intervals. The API and pprof server must be running for this end-to-end check.
Constraints
- The
audittarget must rungovulncheck ./...,golangci-lint runandgo test -racein that order. Stop at the first failure. - The
.github/workflows/backend.ymlworkflow must include a govulncheck step and run tests with-race. - The
backend/scripts/soak.shscript must invokek6 run, sample bothdebug/pprof/goroutineanddebug/pprof/heap, and passbash -n. - After 150 concurrent clients finish their requests, the goroutine count must return to within 15 of baseline within 15 seconds.
- Do not modify the provided tests.
Design direction
Keep the audit target in the Makefile as a short sequence of independent commands. Let Make stop when a command fails rather than hiding errors inside a wrapper.
Keep the CI vulnerability check separate from lint so the workflow reports which gate failed. Production-only linting lets you check the implementation without treating later exercise test files as production code.
Keep the soak script responsible for orchestration and measurement. Let k6 generate traffic, curl collect pprof profiles, and Bash manage the child process and CSV output.
Think about the distinction between a static check and a runtime observation. A clean audit cannot prove that a goroutine returns after a request finishes. A stable goroutine count cannot prove that your code has no data races. Both checks have a separate purpose. Any layout that meets the contract passes.
How to check your work
Run these commands in sequence from the repository root:
go install golang.org/x/vuln/cmd/govulncheck@latest
cd backend
make audit
make test W=6B6
TEST_API_URL=http://localhost:8080 make test W=6B6
./scripts/soak.sh
curl -s "http://127.0.0.1:6060/debug/pprof/goroutine?debug=1" | head -1Keep the API and worker running throughout the soak. The default duration is ten minutes. The end-to-end test needs the API running at http://localhost:8080 and the private pprof listener at 127.0.0.1:6060.
Run the final curl once before the soak and once after it to compare goroutine counts.
Inspect loadtest/soak.csv after the run. Compare the goroutines column against its baseline and check the heap_inuse_bytes column for sustained growth. The script exits non-zero if the final goroutine count exceeds baseline by more than 20.
When a test fails, read its first failing assertion before changing code. It identifies the specific contract that failed, such as a missing audit command, a missing CI flag, an invalid soak script or a goroutine count that remains elevated.
The reference solution passes every check for this exercise. Try the hints first; reading the answer before you have struggled with the problem teaches much less.
Implementation
Run locally
Write the code in your editor inside zomato-prep, then work through this list.
make auditruns vulnerability scanning, production lint and race tests.- CI includes a separate vulnerability-check step and race-enabled tests.
- Production-code lint findings are fixed without changing behaviour.
soak.shrecords goroutine and heap samples inloadtest/soak.csv.- The soak finishes with no more than 20 goroutines above baseline.
- The end-to-end burst test returns within 15 goroutines of baseline.
Commands
cd backend && make auditcd backend && ./scripts/soak.sh # 10 minutes against the running APIcd backend && TEST_API_URL=http://localhost:8080 make test W=6B6Tests
TestW6B6_GoroutinesReturnToBaselineAfterABurstinbackend/e2e/w6_test.goTestW6B6_MakeAuditRunsVulncheckLintAndRaceTestsinbackend/internal/audit/audit_test.goTestW6B6_CIWorkflowRunsGovulncheckinbackend/internal/audit/audit_test.goTestW6B6_SoakScriptSamplesGoroutinesAndHeapinbackend/internal/audit/audit_test.go