DEV Community

Cover image for Preventing Duplicate Event Badge Printing Requests
stampiq
stampiq

Posted on

Preventing Duplicate Event Badge Printing Requests

Preventing Duplicate Event Badge Printing Requests

Imagine an event registration desk where a staff member clicks Print Badge twice because the first request appears to be taking too long.

Without appropriate safeguards, the application could create two print jobs for the same credential.

One approach to reducing this problem is request idempotency.

Define a database constraint

In PostgreSQL, a unique constraint can prevent duplicate job records for the same event, attendee and credential version.

CREATE TABLE badge_print_jobs (
  id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  event_id TEXT NOT NULL,
  attendee_id TEXT NOT NULL,
  credential_version INTEGER NOT NULL,
  status TEXT NOT NULL DEFAULT 'queued',
  UNIQUE (
    event_id,
    attendee_id,
    credential_version
  )
);
Enter fullscreen mode Exit fullscreen mode

Create a print job safely

async function createPrintJob(
  db,
  eventId,
  attendeeId,
  credentialVersion
) {
  const result = await db.query(
    `INSERT INTO badge_print_jobs
       (event_id, attendee_id, credential_version)
     VALUES ($1, $2, $3)
     ON CONFLICT
       (event_id, attendee_id, credential_version)
     DO NOTHING
     RETURNING id`,
    [eventId, attendeeId, credentialVersion]
  );

  return result.rows.length
    ? { status: "created", id: result.rows[0].id }
    : { status: "already_exists" };
}
Enter fullscreen mode Exit fullscreen mode

If two requests arrive with the same identifiers, the database constraint allows only one corresponding job record.

What happens when the printer fails?

Creating one database record does not guarantee that exactly one physical badge will be printed.

A worker must still manage job processing, equipment acknowledgements and ambiguous failures.

Do not automatically retry an uncertain physical print operation without an appropriate reconciliation mechanism.

Handle replacements deliberately

A replacement credential should follow an authorized process rather than bypassing the database constraint accidentally.

For example, an approved replacement may receive a new credential version while the previous credential is revoked.

Practical application

These considerations are particularly relevant to conferences and exhibitions using on-site credential production.

For industry context, StampIQ provides information about its event badge printing services.

This example demonstrates application-level duplicate request prevention. Production systems also require authentication, authorization, durable job processing and printer-specific recovery procedures.

Contributed by the StampIQ team.

Top comments (1)

Collapse
 
hritik_chaudhary_5db0056f profile image
Hritik Chaudhary •

One catch with ON CONFLICT DO NOTHING ... RETURNING: on a conflict it returns no row, so the clerk who double-clicked only gets already_exists and cannot tell whether the first job is queued, printing or failed. Selecting the existing row after a conflict and showing its status gives them something to act on. Two things on the reprint side. The same unique key also blocks a legitimate reprint of a torn or jammed badge, so a separate attempt number that only a deliberate Reprint action increments keeps the dedupe for accidental clicks. For the printer ambiguity you mention, an explicit sent-without-acknowledgement state that waits for a person beats an automatic retry, because the worker cannot know whether paper came out.