Skip to content

Latency: No server-side caching — full AI matching pipeline runs on every request #136

@coderabbitai

Description

@coderabbitai

Problem

Every POST to /jobs/match in backend/controller/jobsController.ts runs the complete job-fetch + AI-scoring pipeline from scratch. For the same user with an unchanged resume this is pure redundant work and is almost certainly the dominant latency source (potentially several seconds per call).

Suggested Fix

Cache results server-side (Redis recommended; in-memory LRU as a quick win), keyed by userId + resumeHash, with a short TTL:

import { createHash } from 'crypto';

// Inside matchJobsHandler, after resolving userId and resumeText:
const resumeHash = createHash('sha256').update(resumeText).digest('hex').slice(0, 16);
const cacheKey = `jobs:${userId}:${resumeHash}`;

const cached = await cache.get(cacheKey);
if (cached) return res.json(JSON.parse(cached));

// ... run full pipeline ...

await cache.set(cacheKey, JSON.stringify(responsePayload), { ttl: 600 }); // 10 min
res.json(responsePayload);

This can reduce p50 latency from seconds to single-digit milliseconds for repeat visits with the same resume.

Impact

🔴 High — likely the single largest latency contributor; affects every request regardless of whether the resume changed.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions