Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 39 additions & 0 deletions .github/scripts/verify-concept.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Proves one concept project is in the state its README promises:
# start/ the checker FAILS, with exactly <startPass> of <total> checks passing
# solution/ the checker passes all <total> checks, and ./mvnw verify is green
# Usage: verify-concept.sh <project path> <startPass> <total>
set -uo pipefail

project="$1"; start_pass="$2"; total="$3"
failed=0

count() { grep -c -F "$1" "$2" || true; }

echo "== $project/start: expecting $start_pass of $total, and a failing exit code"
(cd "$project/start" && ./check) > start.log 2>&1
start_exit=$?
pass=$(count "[PASS]" start.log); fail=$(count "[FAIL]" start.log)
echo " got $pass of $((pass + fail)), exit code $start_exit"
if [ "$pass" != "$start_pass" ] || [ "$((pass + fail))" != "$total" ] || [ "$start_exit" = "0" ]; then
echo " WRONG. Output of ./check in start/:"; cat start.log; failed=1
fi

echo "== $project/solution: expecting $total of $total, and exit code 0"
(cd "$project/solution" && ./check) > solution.log 2>&1
solution_exit=$?
pass=$(count "[PASS]" solution.log); fail=$(count "[FAIL]" solution.log)
echo " got $pass of $((pass + fail)), exit code $solution_exit"
if [ "$pass" != "$total" ] || [ "$fail" != "0" ] || [ "$solution_exit" != "0" ]; then
echo " WRONG. Output of ./check in solution/:"; cat solution.log; failed=1
fi

echo "== $project/solution: ./mvnw verify"
if (cd "$project/solution" && ./mvnw -B -q verify) > verify.log 2>&1; then
echo " green"
else
echo " FAILED:"; tail -n 80 verify.log; failed=1
fi

rm -f start.log solution.log verify.log
exit $failed
105 changes: 105 additions & 0 deletions .github/workflows/concepts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Backend concepts

# Every project under java/concepts is broken on purpose in start/ and fixed in solution/.
# This workflow proves both halves still hold, so the READMEs and guides stay true.

on:
pull_request:
paths:
- "java/concepts/**"
- ".github/workflows/concepts.yml"
- ".github/scripts/verify-concept.sh"
push:
branches: [main]
paths:
- "java/concepts/**"
- ".github/workflows/concepts.yml"
- ".github/scripts/verify-concept.sh"
workflow_dispatch:

concurrency:
group: concepts-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
list:
name: List projects
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.read.outputs.projects }}
steps:
- uses: actions/checkout@v4
- id: read
run: echo "projects=$(jq -c . java/concepts/ci-projects.json)" >> "$GITHUB_OUTPUT"

verify:
name: ${{ matrix.project.path }}
needs: list
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.list.outputs.projects) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "25"
cache: maven
# start/ must fail with the documented count; solution/ must pass everything.
- name: Verify start/ and solution/
run: >
.github/scripts/verify-concept.sh
"${{ matrix.project.path }}"
"${{ matrix.project.startPass }}"
"${{ matrix.project.total }}"

windows-launchers:
name: Windows launchers
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "25"
cache: maven
# Hosted Windows runners cannot run the Postgres containers, so this checks what it can:
# every project's demo.cmd compiles the project and passes its arguments through.
- name: demo.cmd --help in every project
shell: pwsh
run: |
$failed = $false
Get-ChildItem java/concepts -Recurse -Filter demo.cmd | Where-Object { $_.Directory.Name -eq 'solution' } | ForEach-Object {
Write-Host "== $($_.FullName)"
$output = & $_.FullName --help 2>&1 | Out-String
if ($LASTEXITCODE -ne 0 -or $output -notmatch 'Usage') {
Write-Host $output
Write-Host "FAILED (exit code $LASTEXITCODE)"
$failed = $true
} else {
Write-Host "ok"
}
}
if ($failed) { exit 1 }
# Thread safety needs no database, so its whole checker can run on Windows.
- name: check.cmd on thread-safety/solution (all pass)
shell: pwsh
run: |
$output = & java/concepts/junior-mid/06-thread-safety/solution/check.cmd 2>&1 | Out-String
Write-Host $output
if ($LASTEXITCODE -ne 0) { Write-Host "FAILED: expected exit code 0, got $LASTEXITCODE"; exit 1 }
if ($output -match '\[FAIL\]') { Write-Host "FAILED: a check failed"; exit 1 }
- name: check.cmd on thread-safety/start (fails on purpose)
shell: pwsh
run: |
$output = & java/concepts/junior-mid/06-thread-safety/start/check.cmd 2>&1 | Out-String
Write-Host $output
if ($LASTEXITCODE -eq 0) { Write-Host "FAILED: start/ must not pass"; exit 1 }
exit 0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ A collection of hands-on coding interview projects organized by language. Each p
> **Backend concepts:** [java/concepts/](java/concepts/) is a different kind of project: not a timed
> round, but one concept taught step by step. Each is broken first (you run it and watch the problem
> happen), has challenge tasks and a guided version, tests as acceptance criteria, and `start/` and
> `solution/` folders side by side. The first one is
> [Locking](java/concepts/junior-mid/locking/): optimistic vs pessimistic, on Spring Boot 4 and Postgres.
> `solution/` folders side by side. There are eight so far, numbered in the suggested order from
> `01-transactional` to `08-idempotency`: see the [list](java/concepts/README.md).

## Structure

Expand Down Expand Up @@ -91,7 +91,7 @@ interview-prep/
│ ├── karat-drills/
│ ├── secret-storage/
│ ├── concepts/
│ │ └── junior-mid/
│ │ └── junior-mid/ (01-transactional ... 08-idempotency)
│ ├── DELIVERY_HERO.md
│ └── KARAT.md
├── python/
Expand Down
27 changes: 18 additions & 9 deletions java/concepts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ under [`java/`](../).

## Projects

| Track | Project | You watch this go wrong | Status |
| # | Track | Project | You watch this go wrong |
|---|---|---|---|
| Junior / mid | [Locking](junior-mid/locking/) | Two buyers both get the last item in stock | Done |
| Junior / mid | [Indexes](junior-mid/indexes/) | Postgres reads 1,000,000 rows to return 1 | Done |
| Junior / mid | [@Transactional](junior-mid/transactional/) | A transfer fails and the money is gone from the sender | Done |
| Junior / mid | [Fetch types and N+1](junior-mid/fetch-types-n-plus-one/) | One request runs 201 SQL statements | Done |
| Junior / mid | [Idempotency](junior-mid/idempotency/) | One payment is retried and the customer is charged twice | Done |
| Junior / mid | [Thread safety](junior-mid/thread-safety/) | 1,000 requests are answered, the counter says 915 | Done |
| Junior / mid | [REST and error handling](junior-mid/rest-and-error-handling/) | A link checker sends 3 GETs and 3 orders are cancelled | Done |
| Junior / mid | [SQL traps and slow queries](junior-mid/sql-traps-and-slow-queries/) | A report silently drops every customer without a paid order | Done |
| 01 | Junior / mid | [@Transactional](junior-mid/01-transactional/) | A transfer fails and the money is gone from the sender |
| 02 | Junior / mid | [Fetch types and N+1](junior-mid/02-fetch-types-n-plus-one/) | One request runs 201 SQL statements |
| 03 | Junior / mid | [Indexes](junior-mid/03-indexes/) | Postgres reads 1,000,000 rows to return 1 |
| 04 | Junior / mid | [SQL traps and slow queries](junior-mid/04-sql-traps-and-slow-queries/) | A report silently drops every customer without a paid order |
| 05 | Junior / mid | [REST and error handling](junior-mid/05-rest-and-error-handling/) | A link checker sends 3 GETs and 3 orders are cancelled |
| 06 | Junior / mid | [Thread safety](junior-mid/06-thread-safety/) | 1,000 requests are answered, the counter says 915 |
| 07 | Junior / mid | [Locking](junior-mid/07-locking/) | Two buyers both get the last item in stock |
| 08 | Junior / mid | [Idempotency](junior-mid/08-idempotency/) | One payment is retried and the customer is charged twice |

The numbers are the suggested order. Each project stands on its own, so you can start anywhere.

More are planned for `junior-mid/`, `senior/` and `messaging/` (Kafka and SQS, step by step).

Expand Down Expand Up @@ -59,3 +61,10 @@ Nothing else. No local Postgres, no `psql`, no global Maven.
2. **Fix it.** The task's acceptance criteria are tests that ship with the project.
3. **Inspect the fix.** Follow the steps and answer the questions: what does the database do now?
4. Repeat for each alternative fix, then compare them.

## Continuous integration

`.github/workflows/concepts.yml` runs on every change under `java/concepts/`. For each project in
[`ci-projects.json`](ci-projects.json) it proves that `start/` fails with exactly the documented
number of passing checks, and that `solution/` passes all of them. When you add a project, or change
how many checks one has, update that file.
10 changes: 10 additions & 0 deletions java/concepts/ci-projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{ "path": "java/concepts/junior-mid/01-transactional", "startPass": 22, "total": 32 },
{ "path": "java/concepts/junior-mid/02-fetch-types-n-plus-one", "startPass": 12, "total": 24 },
{ "path": "java/concepts/junior-mid/03-indexes", "startPass": 11, "total": 25 },
{ "path": "java/concepts/junior-mid/04-sql-traps-and-slow-queries", "startPass": 17, "total": 33 },
{ "path": "java/concepts/junior-mid/05-rest-and-error-handling", "startPass": 13, "total": 56 },
{ "path": "java/concepts/junior-mid/06-thread-safety", "startPass": 18, "total": 29 },
{ "path": "java/concepts/junior-mid/07-locking", "startPass": 7, "total": 18 },
{ "path": "java/concepts/junior-mid/08-idempotency", "startPass": 15, "total": 32 }
]
Loading
Loading