Implementation of Bulk Document Sending for Signing
Bulk document sending for signing is a scenario where one company sends hundreds or thousands of personalized documents to recipients: employment contracts for bulk hiring, work completion reports to freelancers, data processing consent forms to users.
System Architecture
Bulk sending doesn't execute synchronously—it's a background task with queue and progress tracking:
User uploads CSV/Excel with recipients list
↓
Data validation (email, name, required template fields)
↓
Batch record creation in DB
↓
Job queue: generate personalized documents
├── Substitute data into template
├── Generate PDF
├── Create unique signing link
└── Send email/SMS
↓
Monitoring: who opened, who signed, who ignored
Data Model
CREATE TABLE signing_batches (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(500),
template_id UUID REFERENCES document_templates(id),
initiated_by UUID REFERENCES users(id),
total_count INT NOT NULL,
sent_count INT DEFAULT 0,
signed_count INT DEFAULT 0,
failed_count INT DEFAULT 0,
status VARCHAR(50) DEFAULT 'pending',
-- pending → processing → completed / partially_failed
deadline_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE signing_requests (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
batch_id UUID REFERENCES signing_batches(id),
recipient_email VARCHAR(500) NOT NULL,
recipient_name VARCHAR(500),
recipient_phone VARCHAR(50),
template_data JSONB NOT NULL, -- Data for template substitution
document_id UUID REFERENCES documents(id),
signing_token UUID UNIQUE DEFAULT gen_random_uuid(), -- Unique token for link
status VARCHAR(50) DEFAULT 'pending',
-- pending, generating, sent, opened, signed, declined, expired
sent_at TIMESTAMPTZ,
opened_at TIMESTAMPTZ,
signed_at TIMESTAMPTZ,
reminder_count INT DEFAULT 0,
expires_at TIMESTAMPTZ,
error_message TEXT
);
CSV Upload and Validation
// Parse and validate recipient file
async function processBatchUpload(file: Express.Multer.File, templateId: string) {
const records = await parseCSV(file.buffer, { headers: true });
const template = await db.documentTemplates.findByPk(templateId);
const requiredFields = extractTemplateVariables(template.content);
const errors: ValidationError[] = [];
const validRows: RecipientRow[] = [];
records.forEach((row, index) => {
const rowErrors = [];
if (!row.email || !isValidEmail(row.email)) {
rowErrors.push(`Row ${index + 2}: invalid email`);
}
for (const field of requiredFields) {
if (!row[field]) {
rowErrors.push(`Row ${index + 2}: missing field "${field}"`);
}
}
if (rowErrors.length > 0) {
errors.push(...rowErrors);
} else {
validRows.push(row);
}
});
return { valid: validRows, errors, totalRows: records.length };
}
Queue Processing
// BullMQ worker: processes signing tasks from queue
const signingWorker = new Worker('document-signing', async (job) => {
const { requestId } = job.data;
const request = await db.signingRequests.findByPk(requestId);
try {
await db.signingRequests.update(requestId, { status: 'generating' });
// 1. Generate personalized document
const pdfBytes = await documentGenerator.generate(
request.template,
request.templateData
);
// 2. Store document
const document = await documentStorage.store(pdfBytes, {
batchId: request.batchId,
requestId: request.id,
});
// 3. Create signing link
const signingUrl = `${process.env.APP_URL}/sign/${request.signingToken}`;
// 4. Send notification
await emailService.send({
to: request.recipientEmail,
subject: 'Document awaits your signature',
template: 'signing-invitation',
data: {
recipientName: request.recipientName,
documentName: request.template.name,
signingUrl,
expiresAt: request.expiresAt,
},
});
await db.signingRequests.update(requestId, {
status: 'sent',
documentId: document.id,
sentAt: new Date(),
});
// Update batch counter
await db.signingBatches.increment(request.batchId, 'sent_count');
} catch (error) {
await db.signingRequests.update(requestId, {
status: 'failed',
errorMessage: error.message,
});
await db.signingBatches.increment(request.batchId, 'failed_count');
}
}, {
concurrency: 10, // Parallel processing
connection: redisConnection,
});
Signing Page (No Authorization)
Recipient follows the link https://app.example.com/sign/{token}—no authorization needed, access only by token:
app.get('/sign/:token', async (req, res) => {
const request = await db.signingRequests.findOne({
signingToken: req.params.token,
status: { not: ['expired', 'signed', 'declined'] },
});
if (!request) return res.redirect('/sign/invalid');
if (request.expiresAt < new Date()) {
await db.signingRequests.update(request.id, { status: 'expired' });
return res.redirect('/sign/expired');
}
// Record opening
if (!request.openedAt) {
await db.signingRequests.update(request.id, { openedAt: new Date() });
}
res.render('signing-page', { request, document: request.document });
});
Reminders
// Cron: daily reminder sending
async function sendSigningReminders() {
const pending = await db.signingRequests.findAll({
status: 'sent',
reminderCount: { lt: 3 },
sentAt: { lt: subDays(new Date(), 2) }, // Reminder after 2 days
expiresAt: { gt: new Date() },
});
for (const request of pending) {
const lastReminderAt = request.lastReminderAt || request.sentAt;
const daysSinceLastReminder = differenceInDays(new Date(), lastReminderAt);
if (daysSinceLastReminder >= 2) {
await emailService.sendReminder(request);
await db.signingRequests.update(request.id, {
reminderCount: request.reminderCount + 1,
lastReminderAt: new Date(),
});
}
}
}
Batch Monitoring Dashboard
Progress bar: sent/signed/unopened/expired. Table with status filters. CSV export of recipients and statuses. "Send reminder" button for all open.
Sending Rate Limits
Email providers have limits. For 10K document batch, sending happens at 100–200 emails per minute via queue with throttling. Using Resend—rate limit 100 req/s, Postmark—100 req/s.
Timeline
CSV upload, validation, batch creation, queue-based PDF generation + sending—7–10 days. Signing page with token, reminders, dashboard monitoring—5–7 days.







