HomeCase studiesSpatial Peer-to-Peer Classifieds and Barter Trading Engine

Case study · Adelaide, Australia

Spatial Peer-to-Peer Classifieds and Barter Trading Engine

Consumer classifieds and the local resale economy

Conventional classifieds apps force neighborhood trades into awkward cash-only listings and imprecise suburb text searches, leaving local barter exchanges uncoordinated and prone to double-promised items. We engineered a hyperlocal peer-to-peer marketplace and barter platform built on a PHP and MySQL spatial backend serving native Java Android and Swift iOS applications. Google Maps powers radius discovery with seller-location masking, stateless JWT governs API access, Firebase drives real-time trade negotiation, and SendGrid manages transactional digests.

Industry
Consumer classifieds and the local resale economy
Solution
A neighborhood classifieds and multi-item barter platform comprising native Android and iOS mobile apps, a spatial PHP/MySQL REST backend, and an operations moderation dashboard.
Platforms
Android · iOS · Web & API
Stack
PHP · MySQL · Java · Swift · Firebase · Google Maps
Location
Adelaide, Australia · delivered remotely
Role
Engineering, with the team behind for mobile and QA

Delivered remotely for a business based in Adelaide, Australia. Names withheld by agreement.

Project Overview

Local resale thrives on proximity—nobody drives forty minutes across town for a second-hand bookshelf or a set of gardening tools—yet most classifieds platforms treat geography as an afterthought and force every transaction into a cash price tag. In Adelaide's neighborhood resale scene, users wanted both straightforward local sales and flexible barter swaps where two neighbors bundle spare items or top up a small cash difference. We built a hyperlocal peer-to-peer marketplace and barter trading platform uniting a PHP and MySQL spatial backend with native Java Android and Swift iOS apps, Google Maps discovery, Firebase live negotiation, and SendGrid transactional notifications.

Business Bottleneck

Supporting peer-to-peer barter fundamentally changes marketplace data modeling. In a cash marketplace, a listing has one owner, one price, and one buyer at checkout. In a barter marketplace, a user can offer one or three items from their own inventory—potentially mixed with cash—against someone else's listing, while simultaneously fielding offers from other neighbors on those exact same inventory items. Without strict transactional state guards, traders routinely accepted overlapping offers by mistake. Meanwhile, neighborhood sellers hesitated to post high-value household goods if public map pins exposed their street address.

Architectural Strategy

We separated authoritative inventory and spatial state from ephemeral negotiation chatter. PHP and MySQL own user identity, spatial listing discovery, and an atomic barter state machine governed by stateless JWT access tokens. Firebase handles real-time offer messaging and instant push alerts across Android and iOS, while Google Maps renders privacy-masked neighborhood discovery circles rather than exact rooftops.

Core Capabilities

  • Radius & Map-Clustered Discovery: Buyers browse within tunable kilometer radii using spatial queries and Google Maps clustering that preserves performance in dense suburbs.
  • Multi-Item & Cash-Hybrid Barter Builder: Traders assemble counter-offers combining one or more personal listings with optional cash adjustments inside an explicit propose/counter/accept flow.
  • Automatic Conflict Resolution: Accepting a trade reserves all involved items atomically and notifies competing offer threads immediately.
  • Privacy-Masked Pickup Zones: Public listings display approximate neighborhood rings until both parties confirm a trade and share an agreed meetup pin.
  • Offline-Resilient Image Publishing: Native Java and Swift uploaders resize and orient photos client-side before posting, reducing cellular upload drops.

Technical Architecture

Flow: Android (Java) / iOS (Swift) + Google Maps SDK <-> PHP REST API (JWT Auth) -> MySQL Spatial & Trade State + Firebase (Live Chat/FCM) + SendGrid (Digests/Alerts)

Mobile clients authenticate via login or social flows and receive a short-lived JWT access token alongside a rotating refresh token. When a user pans the Google Maps viewport or adjusts a distance slider, the PHP API computes a bounding box and executes a MySQL spatial query ordered by ST_Distance_Sphere, masking returned coordinates to zone centroids.

Barter negotiations open a linked thread in Firebase Realtime Database referencing an immutable offer ID in MySQL. Counter-offers and final acceptances submit back to the PHP API, which locks the participating listing rows with SELECT ... FOR UPDATE, verifies every bundled item remains available, transitions them to reserved, and triggers Firebase Cloud Messaging and SendGrid notifications for offline counterparties.

Technology Stack

Category Technology detail
Backend API Modular PHP REST services with strict JSON schema validation
Spatial database MySQL 8 with SRID 4326 POINT columns and R-tree spatial indexes
Authentication Stateless JWT access tokens paired with rotating refresh tokens
Android client Native Java app with image compression and map clustering
iOS client Native Swift app with responsive feed caching and trade builder UI
Geolocation & maps Google Maps SDK for radius pickers, clustered pins, and fuzzy zones
Real-time chat & push Firebase Realtime Database and FCM for live offer negotiation
Transactional email SendGrid templates and webhooks for trade alerts and verification
Trust & moderation Automated listing state guards, report queues, and blocklists
Media pipeline Server-side thumbnail generation and EXIF orientation normalization

Engineering Trade-offs & Solutions

Architectural Dilemma Chosen Solution & Rationale
Pure MySQL spatial queries vs. external search index Syncing barter reservation status to an external search engine introduces stale windows where users tap items already reserved seconds earlier. Keeping spatial queries inside MySQL guarantees strong consistency at offer time.
Exact map pins vs. fuzzy neighborhood circles Pinning exact seller coordinates improves travel estimates but compromises home privacy. Masking coordinates to deterministic neighborhood offsets on public feeds protects sellers while keeping radius filtering accurate.
Native Java/Swift clients vs. hybrid web views Smooth 60 fps Google Maps marker clustering, camera multi-pickers, and fluid drag-and-drop barter tray interactions perform noticeably better in native Swift and Java than inside cross-platform WebViews.
Firebase-only trade state vs. PHP transaction authority Letting clients mutate trade acceptance directly in Firebase risks race conditions and tampered bundles. Keeping Firebase strictly for chat delivery and anchoring state transitions in MySQL transactions closes both gaps.

Security & Reliability

All API endpoints validate JWT signatures, audience claims, and token expiration before touching user data, while refresh tokens rotate on every use with reuse detection to flag stolen credentials. Input sanitization and strict media MIME inspection block spoofed image uploads, and rate-limiting shields authentication and messaging endpoints against credential stuffing and automated listing spam. SendGrid webhook listeners track bounces and spam reports automatically, suppressing bad addresses to protect sender reputation.

Performance & Scale

Spatial index bounding boxes prevent full-table scans as neighborhood inventory grows across suburbs, keeping feed queries tightly bounded by latitude/longitude envelopes and category predicates. Client-side image downscaling on Android and iOS trims multi-megabyte phone camera captures before upload, cutting PHP memory usage and keeping feed scrolling brisk over mobile connections. Cursor-based pagination avoids offset drift when new neighborhood listings arrive mid-scroll.

Operational Outcomes

Local buyers and sellers gained a trustworthy way to discover nearby goods without exposing home addresses, while barter traders moved from chaotic text negotiations to structured, conflict-free item swaps. Moderation staff gained clean visibility into flagged listings and trade histories, and native Android and iOS clients delivered responsive map exploration suited to everyday neighborhood trading.

01 — Questions

asked about this kind of project

How do you prevent sellers' exact home addresses from leaking on map views?

Exact coordinates are stored internally for radius sorting in MySQL, but API serializers never return raw home coordinates to browsing clients. Public map endpoints apply deterministic jitter and snap listings to approximate neighborhood circles in Google Maps, revealing precise meetup coordinates only after both parties commit to a trade or meetup.

How does the barter engine prevent someone from promising the same item in two simultaneous trades?

Items linked to an accepted trade transition atomically inside a MySQL transaction from `available` to `reserved`. Any other open barter bundles referencing that item automatically invalidate or prompt the counterparty to revise their offer, eliminating double-commitment disputes.

Why pair MySQL spatial indexes with a PHP backend instead of adding a separate search cluster?

At metropolitan neighborhood scale, bounding-box prefilters combined with MySQL R-tree spatial indexes and `ST_Distance_Sphere` evaluate distance, category, and barter eligibility in a single relational query—avoiding index-lag bugs where a recently traded item still shows up in an external search engine.

How does stateless JWT authentication handle compromised devices or account bans?

Access tokens remain short-lived so stateless validation stays fast across PHP endpoints, while longer-lived refresh tokens are persisted server-side and immediately revocable. Moderator suspensions or password resets revoke the refresh family and write a short-TTL revocation check for active access windows.

Why split live negotiation onto Firebase while keeping listing state in MySQL?

Chat typing indicators, photo exchanges, and counter-offer bubbles benefit from Firebase's low-latency listeners without tying up PHP worker connections. Authoritative trade commitments, item locks, and completion confirmations still execute through MySQL transactions so money-or-barter integrity never depends on client-side writes.

How are SendGrid emails prevented from spamming users during active negotiations?

Notification triggers debounce against active Firebase presence. When a user is actively viewing a chat thread, push and email dispatches are suppressed; SendGrid triggers only for offline missed offers, security events, and batched neighborhood digest summaries.

03 — Similar project?

describe what is different about yours

Build yours.

Tell me what exists, what you need and the deadline. Fixed price for a defined scope, or $55/day (8–9 hours work) with a written plan first.

Solitaire Corporate Park, Makarba, Ahmedabad, Gujarat 380015, India · IST (UTC+5:30) · --:-- IST · Mon–Fri 09:00–18:00 IST · US & EU overlap daily

No newsletter, no CRM. Just a reply.