• 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.

The Safire landing page: Stay Safe Online, Hassle-Free, with an install extension button.
the landing page
A LinkedIn inbox with Safire running: harassing messages hidden behind warnings, with show, report and hide user buttons.
hidden before you read it
A generated evidence report: reference, date, classification and subject information.
the evidence report
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 works
  • A verdict cache

    Redis, keyed by message and platform, so the same message is never paid for twice.

    How it works
  • Evidence reports

    Gemini's findings rendered by Puppeteer into an A4 PDF, safe even when the model's answer isn't.

    How it works
  • The 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

LinkedIn DMs/messagingExtensionMutationObserver · seen idsKeyword list~300 variants, in pageAPIExpress · JWT · zodVerdict cacheRedis · 1 hLoad balancer, five replicas123454 strategies, A/Ba breaker eachGeminiHidden archiveMongoDBEvidenceGemini · Puppeteernot caughtmisshidea sender hidden by five peopleis flagged for everyone
Screen every message, but pay the model only for the ones nothing cheaper could answer; a load balancer spreads the rest over five replicas and steps around any whose breaker is open.

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.

detection cascadecheapest first
seen beforea set lookup
0%
keyword lista scan
0%
redis verdict cacheone read
0%
modelone call
0%

the model answers roughly one message in six

Screening, cheapest first: seen before, a word list, the cache, and only then the model.

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}`);  }}
Four strategies and an A/B mode; the one picked goes first and the rest of the pool is the failover.
Five stand-in replicas, 50 connections, 30 s, median of 3 runs
StrategyRequests a secondp50p95Share to the 40, 40, 80 and 160 ms replicas
Least connections78846 ms166 ms37, 37, 18 and 9%
Round robin40262 ms358 ms25% each
Weighted39755 ms372 msAbout 25% each
Fastest response403125 ms139 ms74 to 95% to one, under 1% to the slow two
A/B, least connections and round robin72747 ms185 ms35, 34, 19 and 13%
On a laptop against local stubs, so the latencies are the replicas' own time plus their queues. Round robin and weighted give the 160 ms replica a quarter of the traffic, so it fills its 16 slots and the rest queue behind it; fastest response sends nearly everything to whichever replica looks quickest until it slows.

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'],};
Three tries at the model's answer, then a safe default for every field the report needs.

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.

Keyboard shortcuts

Anywhere on the site, while you are not typing.

M
Weather sound on or off
E
Copy my email
T
Day or night
S
Change the season
D
Portfolio
?
These shortcuts
Esc
Close what is open