Delivered remotely for a business based in Warsaw, Poland. Names withheld by agreement.
Project Overview
Short-form opinion networks live or die by how fast a user can read a prompt, register a stance, and see where the crowd stands. For a consumer social product launched out of Warsaw, we built the complete native iOS experience in Swift alongside a custom PHP and MySQL API hosted on Google Cloud. Rather than mimicking long-form comment threads, every post centers on a structured binary or multi-option poll enhanced with optional photography, expiration timers, and topic tags. The engineering mandate was straightforward: keep scrolling and voting instantaneous on mobile networks while protecting poll integrity against coordinated spam and duplicate ballots.
Business Bottleneck
Earlier prototypes suffered from three compounding issues that stalled user retention. First, polling endpoints coupled image uploads, vote tally recalculation, and push notification dispatch inside synchronous HTTP request cycles, causing mobile UI freezes whenever a poll gained traction. Second, unverified email-only signups invited automated scripts that skewed public polls within minutes of publication. Third, naively incrementing a single counter column on the central polls table created InnoDB row-lock queues during peak evening traffic, turning a smooth swipe gesture into multi-second spinner delays.
Architectural Strategy
We decoupled interactive voting from heavy side effects and media movement. The Swift client talks directly to Google Cloud Storage via short-lived signed URLs for poll attachments, keeping binary payloads off the PHP application tier. Authentication pairs Twilio phone verification at onboarding with short-lived JWT access tokens so stateless API workers authenticate requests without central session-store round-trips. On the write path, ballots append cleanly and asynchronously trigger Firebase Cloud Messaging alerts and SendGrid digests only after the core vote transaction commits.
Core Capabilities
- Structured Opinion Composer: Users author timed or open-ended polls with two to four choices, topic categorization, and cropped imagery uploaded directly to cloud object storage.
- Instant Consensus Reveal: Casting a vote transitions the Swift card smoothly into live percentage bars while prefetching the next batch of topic-matched cards.
- Verified Identity Onboarding: New accounts pass Twilio SMS one-time passcode checks before publishing or voting, raising the cost of automated account farming.
- Targeted Event Notifications: Firebase Cloud Messaging alerts creators when polls cross participation thresholds, receive replies, or reach their closing timestamp.
- Moderation and Abuse Controls: Staff review flagged prompts, mute repeat offenders, and invalidate compromised refresh token families from an internal operations console.
- Lifecycle Email Workflows: SendGrid handles account verification backups, security alerts, and curated weekly recap emails with bounce and complaint webhook tracking.
Technical Architecture
Flow: Swift iOS Client -> JWT-Authenticated PHP API (Google Cloud) -> MySQL Vote Ledger & Feed Index -> Async Workers -> Firebase FCM / SendGrid / Twilio
The Swift application uses a unidirectional state store backed by URLSession and a lightweight local cache so previously viewed polls remain readable offline. API endpoints accept and emit compact JSON payloads protected by Bearer JWT headers signed with asymmetric keys. Behind the Google Cloud load balancer, stateless PHP workers validate token claims locally before querying Cloud SQL (MySQL).
To eliminate hot-row lock contention on trending polls, vote submissions insert into a poll_votes table governed by a composite unique index on (poll_id, user_id) and an idempotency token column. Read endpoints consult precomputed option tallies refreshed on a sub-second debounce window, ensuring voters immediately see their own ballot reflected client-side while global percentages converge cleanly without locking concurrent writers. Media uploads bypass PHP entirely: the API issues a scoped Google Cloud Storage upload policy, Swift uploads the compressed JPEG directly, and the final poll creation call references only the verified object key.
Technology Stack
| Category | Technology detail |
|---|---|
| Mobile Client | Native Swift (UIKit, URLSession, local CoreData feed cache) |
| Backend Runtime | PHP 8 REST API with strict JSON schema validation |
| Primary Database | MySQL with composite feed indexes and unique vote constraints |
| Authentication | Stateless JWT access tokens with rotating refresh records |
| Phone Verification | Twilio Programmable SMS OTP for Sybil and bot resistance |
| Push Notifications | Firebase Cloud Messaging (FCM) for vote milestones and replies |
| Transactional Email | SendGrid API for account recovery and weekly digest delivery |
| Cloud Infrastructure | Google Cloud Compute Engine, Cloud SQL, and Cloud Storage |
| Media Delivery | Google Cloud Storage signed upload URLs for poll card imagery |
Engineering Trade-offs & Solutions
| Challenge | Architectural Solution |
|---|---|
| Hot-row locking on viral polls | Append-only poll_votes ledger paired with debounced tally aggregation instead of synchronous UPDATE polls SET count = count + 1 per request |
| Duplicate votes on flaky mobile networks | Client-generated idempotency keys plus MySQL composite unique index on (poll_id, user_id) to turn retries into safe no-ops |
| Session revocation with stateless JWT | Short-TTL access tokens combined with revocable MySQL refresh token families so banned devices lose access promptly |
| API bandwidth saturation from photos | Direct-to-Google Cloud Storage signed upload URLs from Swift so PHP workers never buffer raw image streams |
| Automated bot ballot stuffing | Mandatory Twilio SMS OTP verification gated prior to first vote, backed by per-IP and per-prefix rate limiting |
Security & Reliability
All client-to-API traffic enforces TLS with strict payload size limits and schema validation at the PHP boundary. JWT signing keys support rotation via key identifiers (kid) in the token header, preventing forced logouts during routine key rollover. Twilio verification codes expire rapidly, enforce exponential backoff after failed attempts, and store only salted hashes of phone numbers for duplicate-account detection rather than exposing raw numbers across feed endpoints. SendGrid event webhooks run through signature verification so bounced addresses automatically suppress future digest sends, preserving sender reputation. Automated Cloud SQL snapshots and point-in-time recovery logs protect user timelines and vote histories against accidental deletion.
Performance & Scale
Pagination uses cursor-based keyset queries over indexed (created_at, id) tuples rather than OFFSET scans, keeping deep scroll performance flat as poll archives grow. In Swift, feed cells reuse pre-measured layout attributes and downsample images to exact display dimensions before caching, preventing memory spikes during rapid scrolling on older iPhones. Background worker pools absorb notification fan-out to Firebase Cloud Messaging in batched multicast calls, isolating API response times from external push gateway latency. Google Cloud autoscaling rules add PHP API instances horizontally on CPU and request-queue thresholds without requiring sticky sessions.
Operational Outcomes
Moving media transfers to signed cloud storage and decoupling vote aggregation removed the request-queue bottlenecks that previously degraded peak evening browsing. Trust and safety teams gained deterministic enforcement controls capable of halting coordinated spam campaigns through phone-verified onboarding and immediate refresh-token revocation. For end users, the Swift feed delivers responsive, jitter-free card transitions and dependable real-time poll results whether browsing on home broadband or commuting across mobile cells.