Project Workshop — Go gRPC Microservice
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Go · gRPC · gin · PostgreSQL · Docker
Expected effort: 15–24 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | types/structs/interfaces/embedding produces the specified behavior inside Go basics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | goroutines + channels (unbuffered/buffered/select/done pattern) produces the specified behavior inside Go basics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | defer/panic/recover produces the specified behavior inside Go basics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | error handling: errors.Is/As/wrapping produces the specified behavior inside Go basics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.5 | packages + modules: go.mod/go.sum produces the specified behavior inside Go basics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | net/http standard library handlers produces the specified behavior inside Go for backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | gin framework: routing/middleware/binding/validation produces the specified behavior inside Go for backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | database/sql + sqlx for PostgreSQL produces the specified behavior inside Go for backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | gRPC: .proto file, service definition, unary + streaming produces the specified behavior inside Go for backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | testing: TestXxx, table-driven tests, t.Parallel(), benchmarks produces the specified behavior inside Go for backend | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1project/2├── cmd/{server,gateway}/main.go3├── internal/{domain,service,repository,transport}/4├── proto/user/v1/user.proto5├── migrations/6├── tests/7├── go.mod8└── DockerfileBuild plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Go basics | types/structs/interfaces/embedding; goroutines + channels (unbuffered/buffered/select/done pattern); defer/panic/recover | Demonstration plus focused tests |
| 2 | Go for backend | net/http standard library handlers; gin framework: routing/middleware/binding/validation; database/sql + sqlx for PostgreSQL | Demonstration plus focused tests |
| 3 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1package main2
3import (4 "context"5 "encoding/json"6 "errors"7 "net/http"8 "time"9)10
11type User struct { ID string `json:"id"`; Name string `json:"name"` }12type Repository interface { Get(context.Context, string) (User, error) }13
14func userHandler(repo Repository) http.HandlerFunc {15 return func(w http.ResponseWriter, r *http.Request) {16 ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)17 defer cancel()18 user, err := repo.Get(ctx, r.PathValue("id"))19 if errors.Is(err, ErrNotFound) { http.Error(w, "not found", http.StatusNotFound); return }20 if err != nil { http.Error(w, "unavailable", http.StatusServiceUnavailable); return }21 w.Header().Set("Content-Type", "application/json")22 json.NewEncoder(w).Encode(user)23 }24}Expected result
1The handler propagates cancellation, maps domain errors to HTTP status, and writes a typed JSON response.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | package main | Implements the next go statement in the example's data flow. |
| 3 | import ( | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 4 | "context" | Implements the next go statement in the example's data flow. |
| 5 | "encoding/json" | Implements the next go statement in the example's data flow. |
| 6 | "errors" | Implements the next go statement in the example's data flow. |
| 7 | "net/http" | Implements the next go statement in the example's data flow. |
| 8 | "time" | Implements the next go statement in the example's data flow. |
| 9 | ) | Implements the next go statement in the example's data flow. |
| 11 | type User struct { ID string \json:"id"\; Name string \json:"name"\ } | Implements the next go statement in the example's data flow. |
| 12 | type Repository interface { Get(context.Context, string) (User, error) } | Implements the next go statement in the example's data flow. |
| 14 | func userHandler(repo Repository) http.HandlerFunc { | Implements the next go statement in the example's data flow. |
| 15 | return func(w http.ResponseWriter, r *http.Request) { | Returns the observable result to the caller and ends this invocation. |
| 16 | ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 17 | defer cancel() | Defines failure translation or cleanup that must run around the protected operation. |
| 18 | user, err := repo.Get(ctx, r.PathValue("id")) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 19 | if errors.Is(err, ErrNotFound) { http.Error(w, "not found", http.StatusNotFound); return } | Evaluates the condition and enters this branch only when it is truthy. |
| 20 | if err != nil { http.Error(w, "unavailable", http.StatusServiceUnavailable); return } | Evaluates the condition and enters this branch only when it is truthy. |
| 21 | w.Header().Set("Content-Type", "application/json") | Implements the next go statement in the example's data flow. |
| 22 | json.NewEncoder(w).Encode(user) | Implements the next go statement in the example's data flow. |
| 23 | } | Implements the next go statement in the example's data flow. |
| 24 | } | Implements the next go statement in the example's data flow. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Go basics | Comparing wrapped errors directly or parsing error strings breaks as soon as context is added. | Wrap with operation context, match stable sentinel/types through Is/As, and commit go.mod/go.sum. |
| Go for backend | Calling t.Parallel with shared mutable fixtures or benchmarking compiler-eliminated work produces misleading results. | Capture each case variable, use -race, report allocations, and benchmark representative data outside setup timing. |
Engineering checklist for this stack
- To do: validate CLI inputs before domain operations
- To do: use explicit exit codes and deterministic output
- To do: close files, sessions, and network clients
- To do: separate domain logic from input/printing
- To do: measure large-input memory behavior
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1func TestCreateUser(t *testing.T) {2 t.Parallel()3 cases := []struct{name string; input *CreateUserRequest; code codes.Code}{4 {"valid", &CreateUserRequest{Name: "Dev"}, codes.OK},5 {"empty name", &CreateUserRequest{}, codes.InvalidArgument},6 }7 for _, tc := range cases {8 tc := tc9 t.Run(tc.name, func(t *testing.T) {10 t.Parallel()11 _, err := service.CreateUser(context.Background(), tc.input)12 if status.Code(err) != tc.code { t.Fatalf("got %v", err) }13 })14 }15}Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?