Skip to content

Real-Time Geolocation Updates for Artisans #299

Description

@ohamamarachi474-del

Layer: Backend API / Redis
Effort: Medium (3–5h)

Artisan locations are currently static. To provide a true "Uber-like" proximity matching experience, we need a high-frequency ingestion endpoint that allows artisan mobile devices to update their coordinates in real-time.

Because this endpoint will be hit frequently (e.g., every 10–30 seconds while the artisan app is open), it must strictly avoid heavy PostgreSQL writes and instead rely entirely on our Redis in-memory datastore.

Required Changes

1. Fast Geolocation Endpoint

  • Create a PUT /api/v1/artisans/location endpoint in backend/app/api/v1/endpoints/artisan.py.
  • Secure the endpoint using Depends(require_artisan) so only authenticated artisans can update their location.
  • The request payload should accept simple latitude and longitude floats.

2. Redis Geospatial Indexing

  • In backend/app/services/geolocation.py, implement a method to handle the Redis GEOADD command.
  • The Redis key should be a spatial index (e.g., artisans:locations) where the member is the artisan_id.
  • Crucial: Implement a TTL (Time-To-Live) mechanism. If an artisan closes their app or loses signal, their location should expire from the map after ~15 minutes to prevent clients from booking "ghost" artisans who are no longer online.

Acceptance Criteria

  • PUT /artisans/location successfully accepts coordinate payloads and strictly requires artisan authentication.
  • Submitting a location correctly updates or inserts the artisan into the Redis GEOADD index.
  • No synchronous PostgreSQL database writes occur during the location update to ensure maximum throughput.
  • Artisan locations automatically expire/drop from the Redis index after 15 minutes of inactivity.
  • Unit tests verify that unauthorized users (Clients) cannot update an artisan's location.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions