Skip to content

Shared event contracts, health probes, gateway validation - #5

Open
coderconnoisseur wants to merge 1 commit into
sync-master-phase1from
cleanup-events-health
Open

coderconnoisseur wants to merge 1 commit into
sync-master-phase1from
cleanup-events-health

Conversation

@coderconnoisseur

@coderconnoisseur coderconnoisseur commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #4 (`sync-master-phase1`, the Phase 1 follow-ups synced into `master`). Merge #4 first, then retarget this PR to `master`.

What changed

  • Shared event contracts (`pkg/events`): `RideRequestedEvent`, `RidePricedEvent`, `RideMatchedEvent`, `RideUnmatchedEvent` and `Location` defined once, with explicit snake_case JSON tags and a `v` field (version 1). Pricing, matching, assignment and api-gateway import them. Round-trip JSON tests included. This fixes the `RideId` / `RideID` drift in pricing.
  • Dead code removed: api-gateway `LogPublisher`, `pricing-service/internal/ports/`, and `matching-service/internal/ports/consumer.go` (an unused consumer interface). Grepped to confirm no imports.
  • Gateway validation: `lat`/`lng` are pointer fields, so a valid `0` is accepted. Latitude must be in [-90, 90] and longitude in [-180, 180]; anything else returns 400 and names the field. Handler tests use `httptest` with a fake publisher.
  • Health and readiness on api-gateway, pricing, matching and assignment:
    • `GET /health` is liveness and always returns 200 while the process runs.
    • `GET /ready` returns 200 only when dependencies answer, within a 1 s budget. The Kafka check dials the first reachable broker. Matching also checks Redis `PING`. Failing checks are listed in a 503 body.
    • Shared implementation in `pkg/health`, with unit tests using injectable checks.

Deploy note: wire format change

Event JSON keys are now snake_case (`ride_id`, `requested_at`, `matched_at`, `driver_id`, `failed_at`, `surge_multiplier`, `pickup`, `drop`) and every event carries `"v": 1`. Previously keys were Go field names (`RideID`, `RequestedAt`, `MatchedAT`, ...).
Producers and consumers all ship in this PR, so a consistent deploy works. But drain and recreate the `ride.*` topics (or reset consumer-group offsets) before starting the new build, so old and new payloads are not mixed on the same topic.

Not in this PR

  • Logical commits: this is a single commit, grouped by the four items above.
  • The README and architecture diagram are in the next PR (stacked on this one).

pkg/events: one definition of Location, RideRequested, RidePriced,
RideMatched and RideUnmatched with snake_case JSON tags and a `v`
version field (1). Pricing, matching, assignment and api-gateway import
these instead of keeping their own copies. This also fixes the RideId /
RideID drift in pricing.

Wire change: event JSON keys are now snake_case (ride_id, requested_at,
matched_at, ...) and carry "v". Producers and consumers ship together,
but drain and recreate ride.* topics (or reset consumer offsets) when
deploying so old and new payloads are not mixed.

pkg/health: Liveness (always 200) and Readiness (checks run concurrently
under a timeout; 503 lists failing checks) plus a Kafka check that dials
the first reachable broker. Served on /health and /ready by api-gateway,
pricing, matching and assignment. Matching also checks Redis PING.

api-gateway: coordinates are pointers so a valid 0 is accepted; lat must
be within [-90, 90] and lng within [-180, 180], otherwise 400 with the
offending field named.

Dead code removed: api-gateway LogPublisher, pricing-service ports/,
matching-service ports/consumer.go.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant