AgentSkillsCN

backend-development

当用户询问“异步模式”“Promise.all”“并行执行”“Firebase 函数”“Webhook 处理器”“Cron 作业”“冷启动”“超时”“Pub/Sub”“后台处理”“消息队列”“扇出”“事件驱动”,或任何 Node.js/Firebase 后端开发相关话题时,可运用此技能。它将提供 async/await 模式、函数配置、Pub/Sub 消息传递,以及可扩展的后台处理方案。

SKILL.md
--- frontmatter
name: backend-development
description: Use this skill when the user asks about "async patterns", "Promise.all", "parallel execution", "Firebase functions", "webhook handlers", "cron jobs", "cold start", "timeout", "pubsub", "background processing", "message queue", "fan-out", "event-driven", or any Node.js/Firebase backend patterns. Provides async/await patterns, function configuration, Pub/Sub messaging, and scalable background processing.

Node.js & Firebase Functions Patterns

Quick Reference

TopicReference File
Promise.all, Parallel Execution, Chunkingreferences/async-patterns.md
Pub/Sub, Fan-out, Message Orderingreferences/pubsub.md
Function Sizing, Webhooks, Cron Jobsreferences/firebase-functions.md
Firestore Queues, Priority Queuesreferences/queue-patterns.md

Async/Await Quick Patterns

javascript
// Parallel (GOOD)
const [customers, settings, tiers] = await Promise.all([
  getCustomers(),
  getSettings(),
  getTiers()
]);

// Avoid await in loops (BAD)
for (const customer of customers) {
  await updateCustomer(customer); // Sequential!
}

// Use Promise.all instead (GOOD)
await Promise.all(customers.map(c => updateCustomer(c)));

Firebase Functions Sizing

Function TypeMemoryTimeout
Simple API handler256MB60s
Webhook handler256-512MB60s
Data sync (large)1GB540s

Webhook Handlers (CRITICAL)

Shopify requires response within 5 seconds!

javascript
// Queue and respond fast
app.post('/webhooks/orders/create', async (req, res) => {
  if (!verifyHmac(req)) {
    return res.status(401).send('Unauthorized');
  }

  await webhookQueueRef.add({
    type: 'orders/create',
    payload: req.body
  });

  res.status(200).send('OK');
});

Background Processing Decision

MethodUse CaseVolume
Firestore triggerSimple queuingLow-Medium
Cloud TasksDelayed processing, rate limitsMedium
Pub/SubHigh volume, fan-out, scalingHigh

See cloud-tasks skill for delayed/scheduled patterns.


Checklist

code
- Independent async operations use Promise.all
- No await inside loops
- Functions right-sized (memory, timeout)
- Webhooks respond < 5 seconds
- Heavy processing in background queue
- Proper error handling with try-catch
- High-volume events use Pub/Sub fan-out
- Delayed tasks use Cloud Tasks