- hackathon
- 2025
- Chrome extension
- Load balancer
- Two first places
Harassment in LinkedIn DMs usually gets read before anyone can report it. Safire reads LinkedIn's page as it changes, screens every incoming message, hides abuse behind a warning, flags a sender once five different people have hidden them, and turns their messages into a PDF evidence report. Four of us built it, and it took first place at HackWIE 3.0 and Code Kshetra 2.0.
It is a Chrome extension backed by an Express API and a Gemini moderation service, and it screens cheapest first: a list of abusive words, then verdicts already cached, and only then the model. My part was the backend (the API, the load balancer across five moderation replicas, the verdict cache and the evidence reports) and, in the extension, the popup and the login hand-off.



- Type
- hackathon
- Role
- The backend, and the extension's popup
- When
- Jan to Feb 2025, polished through July
- Team
- Four of us
- Stack
- Plasmo (MV3), React, Node, Express, MongoDB, Redis, Gemini, Puppeteer, Docker, Next.js
- Links
- safire-five.vercel.appDemoCode
My part
The backend
The Express and MongoDB API: auth, hiding senders and messages, the archive with filters and paging, and stats.
A load balancer, from scratch
Five moderation replicas behind four strategies, A/B tested on live traffic, with health checks and a circuit breaker for each.
How it worksA verdict cache
Redis, keyed by message and platform, so the same message is never paid for twice.
How it worksEvidence reports
Gemini's findings rendered by Puppeteer into an A4 PDF, safe even when the model's answer isn't.
How it worksThe crowd rule
A sender is flagged once five different people have hidden them.
The extension's popup
Preferences, blocked words, the hidden-message archive and reports, with login handed over from the dashboard.
How it fits together
Cheapest first
Most messages never reach the model. A word list in the page catches the obvious, a shared Redis cache answers anything judged in the last hour, and only what's left costs a call.
the model answers roughly one message in six
A load balancer, written from scratch
The model ran on free tiers, and free tiers run out, usually in the middle of a demo. So moderation moved into its own stateless service on five replicas, and I wrote the load balancer in front of them in Node: least connections, round robin, weighted and fastest response, one chosen per deployment. Whichever strategy picks first, the rest of the pool is the failover, each tried once, so a request fails only when every replica has.
Every replica sits behind its own circuit breaker: ten failures open it for thirty seconds, then one half-open request decides whether it closes. A health check every 50 seconds marks a replica unhealthy after five failed checks and healthy again after two passes, so one blip doesn't flip it. Every response names the replica that served it and the strategy that chose it, in two headers, which is what makes the rest measurable.
The balancer carries its own load test, /test-servers, which counts what each replica served from those headers. Against five stub replicas, 200 requests landed 40 on each; with two of them failing, all 200 still succeeded, and their breakers opened after 10 to 12 calls.
To choose between strategies on evidence rather than taste, it can A/B test two on live traffic: each request is given one, and each strategy's share, success rate and p50 and p95 latency are kept side by side.
I measured it on my laptop too, its code unchanged, in front of five local stand-in replicas: two answering in 40 ms, one in 80 and one in 160, each 16 requests at a time, and one failing every call while still passing its health checks. Under 50 connections for 30 s, least connections split traffic by speed and carried about twice round robin's throughput at under half its p95. In all 30 runs the failing replica took 10 to 40 requests before its breaker shut it out, each was retried on the next replica, and no client saw an error.
On its own the balancer costs 0.25 to 0.5 ms of CPU a request, so one Node process served 2,100 to 4,500 requests a second, depending on what else the laptop was running. In front of replicas that take 40 ms, it added under 1 ms at p50 and 7 to 54 ms at p95.
api/moderation/detect-harassment.js
const strategies = { 'weighted': getWeightedServer, 'least-connections': getLeastConnectionsServer, 'fastest-response': getFastestResponseServer, 'round-robin': getRoundRobinServer};// "ab" gives each request one of two strategies, to compare them liveconst pickStrategy = () => { const { strategy, abStrategies, abSplit } = config.loadBalancer; const name = strategy === 'ab' ? (Math.random() < abSplit ? abStrategies[0] : abStrategies[1]) : strategy; return strategies[name] ? name : 'least-connections';};// the strategy picks who goes first, the rest are the failoverconst strategyName = pickStrategy();const first = strategies[strategyName]();const ordered = first ? [first, ...availableServers.filter(server => server !== first)] : availableServers;for (const server of ordered) { try { result = await handleRequest(server, req); recordStrategy(strategyName, true, Date.now() - startTime); return res.json(result); } catch (error) { errors.push(`${server.url}: ${error.message}`); }}| Strategy | Requests a second | p50 | p95 | Share to the 40, 40, 80 and 160 ms replicas |
|---|---|---|---|---|
| Least connections | 788 | 46 ms | 166 ms | 37, 37, 18 and 9% |
| Round robin | 402 | 62 ms | 358 ms | 25% each |
| Weighted | 397 | 55 ms | 372 ms | About 25% each |
| Fastest response | 403 | 125 ms | 139 ms | 74 to 95% to one, under 1% to the slow two |
| A/B, least connections and round robin | 727 | 47 ms | 185 ms | 35, 34, 19 and 13% |
Evidence that survives bad model output
Gemini turns a sender's hidden messages into findings, patterns and a risk level, and Puppeteer renders them into an A4 PDF from a Handlebars template.
The model's answer is never trusted as it comes: parse, strip the formatting and parse again, fall back to what can be read from the text, then type-check every field, so the renderer never gets a broken shape.
api/user/report.js
let parsedResponse;try { parsedResponse = JSON.parse(text);} catch (parseError) { const cleanedText = text .replace(/```json\n?|\n?```/g, '') .replace(/\\n/g, ' ') .trim(); try { parsedResponse = JSON.parse(cleanedText); } catch (secondParseError) { parsedResponse = { severityAssessment: text.includes('HIGH') ? 'HIGH' : text.includes('MEDIUM') ? 'MEDIUM' : 'LOW', recommendedActions: ['Review evidence manually'], }; }}const sanitizedResponse = { severityAssessment: parsedResponse.severityAssessment || 'MEDIUM', keyFindings: Array.isArray(parsedResponse.keyFindings) ? parsedResponse.keyFindings .filter(item => item && typeof item === 'string') : ['Manual review recommended'],};What breaks first at 10× the traffic
The reports. Each one launches its own headless Chrome, which is fine for a demo and the first thing to fall over under load. The plan: a render queue in front of a pool of Puppeteer browsers that reuse their pages, sized by memory, every render on a timeout.
The stream of messages. Today every DM is its own request. The plan is to stream moderation messages through Kafka, settle most of them in a split second with jev before the model ever sees them, and batch messages in the extension instead of sending them one at a time.
The cache. One Redis holds every verdict; past what one instance holds, it shards by a hash of the message.
Next. A labelled message set to measure detection accuracy, the message stream through Kafka, and a Chrome Web Store listing.
