Skip to content

perf(common): GeolocationMiddleware runs geoip lookup on every route including health checks #668

Description

@phertyameen

Summary

app.module.ts applies geolocation enrichment globally:

consumer.apply(GeolocationMiddleware).forRoutes('*');

This means every request pays a geoip-lite lookup, including:

  • /health (hit continuously by load balancers and referenced by the graceful-shutdown probe in main.ts),
  • /api Swagger document routes,
  • all pre-auth auth/* traffic.

Infrastructure probes get geolocation side effects for IPs that will never be users, and the lookup cost lands on the hottest paths.

Proposal

  1. Exclude infrastructure paths:
    consumer.apply(GeolocationMiddleware)
      .exclude('health', 'api/(.*)')
      .forRoutes('*');
  2. Audit what consumes the enriched fields downstream (the analytics module recently gained PII hashing in event metadata - confirm country/city granularity is intentional there).
  3. Add unit tests mirroring the style used for CorrelationIdMiddleware, including exclusion cases.

Acceptance criteria

  • Health/Swagger paths bypass geolocation enrichment.
  • Business routes still receive enrichment data.
  • Middleware covered by unit tests including exclusion cases.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions