• Residence: Bosnia & Herzegovina
  • City: Bijeljina
  • Age: 26
DOWNLOAD CV
Back to Blog

Building a Self-Hosted Sentry Alternative: Architecture and Lessons from BugCatch

· Đorđije Lazarević · 4 min read

BugCatch started as a question: what would it take to build my own error tracker in the category of Sentry, Datadog and New Relic? It is now a working platform with SDKs for JavaScript/TypeScript and Java, distributed tracing, uptime monitoring and public status pages. This is how it is built, and what I would tell anyone attempting the same.

Three components

  • SDK, installed in the monitored application. It captures errors, unhandled promise rejections and breadcrumbs, parses stack traces, attaches user context and sends a structured payload.
  • Ingest API, the highest-traffic endpoint. It must answer fast no matter what.
  • Event processor, a BullMQ worker that does the real work: grouping, regressions, counters.

Rule one: the ingest endpoint never waits

If your error tracker slows down the app it monitors, it is worse than nothing. The ingest endpoint does three things only: authenticate the SDK key, compute a fingerprint, put the event on a queue. Then it returns 200.

@Post('ingest')
@HttpCode(200)
async ingest(@Headers('x-api-key') key: string, @Body() payload: IngestPayload) {
  const project = await this.projectKeys.resolve(key);
  if (!project) throw new UnauthorizedException();

  await this.events.add(
    'event',
    { projectId: project.id, fingerprint: fingerprint(payload), payload },
    { attempts: 5, backoff: { type: 'exponential', delay: 1000 }, removeOnComplete: true },
  );
  return { ok: true };
}

Authentication must not hit the database on every event. The SDK key is resolved from Redis with a five-minute TTL, and only a cache miss falls back to MySQL:

async resolve(key: string): Promise<{ id: string } | null> {
  const cached = await this.redis.get(`sdk-key:${key}`);
  if (cached) return JSON.parse(cached);

  const project = await this.projects.findOne({ where: { sdkKey: key } });
  if (!project) return null;

  const value = { id: project.id };
  await this.redis.set(`sdk-key:${key}`, JSON.stringify(value), 'EX', 300);
  return value;
}

Grouping: one bug, one issue

Four thousand crashes from the same bug should be one issue with a counter, not four thousand rows in a list. BugCatch hashes the error type, message, file and line into a SHA256 fingerprint:

import { createHash } from 'node:crypto';

export function fingerprint(e: { type: string; message: string; filename?: string; line?: number }) {
  return createHash('sha256')
    .update([e.type, e.message, e.filename ?? '', e.line ?? ''].join('|'))
    .digest('hex');
}

The lesson here: messages often contain variable data such as IDs, amounts or timestamps ("Order 4821 not found"). If you hash them raw, one bug becomes thousands of issues. Normalising numbers and UUIDs before hashing, or letting the SDK send an explicit fingerprint, keeps grouping useful.

The processor

The worker runs with a concurrency of five and exponential-backoff retries. For each event it gets or creates the issue by fingerprint, stores the event, increments counters atomically in the database and adds the user to a Redis set, so "affected users" is a cheap SCARD instead of a COUNT(DISTINCT ...) over millions of rows.

Regressions are handled here too: when a resolved issue receives a new event, it re-opens and the project owner gets an email. Ignored issues stay ignored, but their events are still recorded.

Averages hide the problem

For performance monitoring, BugCatch tracks p50, p75, p95 and p99 latency per route, plus throughput and error rate. An endpoint with a 120 ms average can still have one request in a hundred taking four seconds, and those are the requests users complain about.

Alerts people do not mute

  • Every alert has a cooldown. Slow queries, high CPU and memory alerts fire once, not on every sample.
  • Uptime checks run every five minutes and retry three times before marking a URL as down. Cron heartbeats alert after one missed ping.
  • Alerts go where the team already is: Slack, Microsoft Teams, PagerDuty, Telegram or a webhook.
  • A weekly digest summarises activity, so nobody has to open the dashboard to know if things are getting worse.

Retention from day one

Error data grows without limit. A monthly job purges old events, stale issues and API metrics in small batches, so the cleanup itself never locks the tables the ingest pipeline writes to.

Should you build your own?

For most teams, no: hosted Sentry is excellent, and their self-hosted edition exists if data must stay on your servers. Building your own makes sense when you need full control over where data lives, want pricing that does not grow with event volume, or, as in my case, want to understand every layer of an observability product. It taught me more about queues, caching and data retention than any client project.

You can see BugCatch at bugcatch.app and read the full project case study.

Planning a React Native app?

I take on freelance projects for clients across DACH and the EU: React and Next.js web apps, React Native mobile apps and NestJS backends, from architecture to production. Remote, CET time zone.