microservices

Seeded cross-cutting service defects — missing timeouts, non-idempotent consumers, PII in traces.

9 deliberate defects, each with a marker naming the rule in standards/ it breaks. It measures recall: how many of the defects the reviewer flags at their severity or higher. The pass condition is that all 5 BLOCKER defects are flagged.

Because each marker names a rule, the scorer also grades attribution. A reviewer that finds the bug but cites the wrong rule counts as caught, and separately as misattributed.

Running it

Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.

seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.

terminal
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>

Flags and output are on redline metrics.

The 9 defects

SeedSeverityRule it violatesDefect
1BLOCKERmicroservices/non-idempotent-consumerat-least-once consumer with no idempotency — a redelivery
3BLOCKERmicroservices/missing-timeoutoutbound call with no timeout — the default is infinite
4BLOCKERmicroservices/swallowed-errorsnon-2xx treated as success
5BLOCKERmicroservices/unversioned-breaking-changebreaking change to a published contract with no version bump:
7BLOCKERmicroservices/pii-in-telemetryPII in a metric label — unbounded cardinality and a data-exposure leak
2HIGHmicroservices/dual-write-no-outboxDB write and publish in one logical step with no outbox —
6HIGHmicroservices/retry-without-backoffretries with no backoff or jitter — turns a blip into a thundering herd
8HIGHmicroservices/readiness-liveness-conflatedreadiness that always reports healthy — traffic keeps arriving while
9HIGHmicroservices/unbounded-workunbounded batch accepted from external input

Scoring

The score reports BLOCKER recall, false positives, and rule attribution. The canary appends it to data/seed-scores.jsonl and fails the run if BLOCKER recall drops below 1.0 or the clean corpus attracts a false positive. Of the 9 defects here, 5 BLOCKER and 4 HIGH — only the BLOCKER count is a pass condition.

Adding a defect

Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.

The full file

seeded/microservices/seeded_violations_service.ts · 66 lines · 2.7 KB
// DO NOT MERGE — Redline validation seed for the cross-cutting microservice rules.
// Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
// citing that rule id. Score with scripts/score-seeds.mjs.

type ChargeMessage = { messageId: string; accountId: string; amountMinor: number };

const db = {} as { charge(a: string, m: number): Promise<void>; wasApplied(id: string): Promise<boolean> };
const bus = {} as { publish(topic: string, payload: unknown): Promise<void> };

export class ChargeConsumer {
  // SEED 1 [BLOCKER] (microservices/non-idempotent-consumer) at-least-once consumer with no idempotency — a redelivery
  // double-charges the customer
  async onMessage(msg: ChargeMessage) {
    await db.charge(msg.accountId, msg.amountMinor);

    // SEED 2 [HIGH] (microservices/dual-write-no-outbox) DB write and publish in one logical step with no outbox —
    // a crash here leaves the ledger and the topic permanently inconsistent
    await bus.publish('charges.applied', { accountId: msg.accountId });
  }
}

export async function callPricing(accountId: string) {
  // SEED 3 [BLOCKER] (microservices/missing-timeout) outbound call with no timeout — the default is infinite
  const res = await fetch(`https://pricing.internal/quote/${accountId}`);

  // SEED 4 [BLOCKER] (microservices/swallowed-errors) non-2xx treated as success
  if (!res.ok) {
    console.error('pricing failed');
  }
  return res.json();
}

// SEED 5 [BLOCKER] (microservices/unversioned-breaking-change) breaking change to a published contract with no version bump:
// `msisdn` was returned by v1 consumers and is now removed and retyped
export type QuoteResponseV1 = {
  accountId: string;
  amount: number; // was `amountMinor: string`
};

export async function retry(fn: () => Promise<void>) {
  // SEED 6 [HIGH] (microservices/retry-without-backoff) retries with no backoff or jitter — turns a blip into a thundering herd
  for (let i = 0; i < 5; i++) {
    try {
      return await fn();
    } catch {
      continue;
    }
  }
}

// SEED 7 [BLOCKER] (microservices/pii-in-telemetry) PII in a metric label — unbounded cardinality and a data-exposure leak
export function recordCharge(metrics: { inc(name: string, labels: object): void }, msisdn: string) {
  metrics.inc('charges_total', { msisdn });
}

// SEED 8 [HIGH] (microservices/readiness-liveness-conflated) readiness that always reports healthy — traffic keeps arriving while
// the dependency is down
export function ready() {
  return { status: 'ok' };
}

// SEED 9 [HIGH] (microservices/unbounded-work) unbounded batch accepted from external input
export async function bulk(ids: string[]) {
  return Promise.all(ids.map((id) => callPricing(id)));
}