惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园_首页
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
美团技术团队
IT之家
IT之家
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
博客园 - 叶小钗
M
MIT News - Artificial intelligence
B
Blog RSS Feed
有赞技术团队
有赞技术团队
Y
Y Combinator Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
The Hub Pattern: Keeping Supabase Edge Functions Under 50
kanta13jp1 · 2026-04-28 · via DEV Community

kanta13jp1

The Hub Pattern: Keeping Supabase Edge Functions Under 50

Supabase Edge Functions have an implicit constraint: there's a practical limit to how many you should deploy. In my project, I've made this explicit as the [EF-CAP-50] rule: 50 functions maximum, enforced by CI.

The pattern that makes this possible is the hub pattern.

The Problem: EF Count Creeps Up

Early in the project, I followed the natural path of one-feature-one-EF:

check-competitor-updates
get-competitor-features
update-competitor-pricing
check-competitor-availability
competitor-monitoring-run
...

Enter fullscreen mode Exit fullscreen mode

That's 5 functions just for competitor monitoring. At 20 features, you've consumed 20 slots. The trajectory is unsustainable.

The Hub Pattern: N Features in 1 EF

// supabase/functions/admin-hub/index.ts
serve(async (req) => {
  const { action, params } = await req.json();

  switch (action) {
    case 'competitor.check':    return competitorCheck(params);
    case 'competitor.pricing':  return competitorPricing(params);
    case 'competitor.features': return competitorFeatures(params);
    case 'wbs.priority_for_instance': return wbsPriority(params);
    case 'wbs.update_progress': return wbsUpdateProgress(params);
    default:
      return new Response('Unknown action', { status: 400 });
  }
});

Enter fullscreen mode Exit fullscreen mode

One admin-hub EF handles multiple actions. Features grow; the EF count doesn't.

Current Hub Structure

Hub EF Actions handled
admin-hub competitor.check / pricing / features / wbs.*
schedule-hub digest.run / daily.report / cs.check
ai-hub judgment.get / horse.predict / writing.assist
tools-hub wbs.priority_for_instance / wbs.update_progress / notify.*

Four hubs handle ~35 actions. If each action were a separate EF, that would be 35 functions. Instead: 4.

Type-Safe Action Routing

// _shared/action-types.ts
type AdminHubAction =
  | 'competitor.check'
  | 'competitor.pricing'
  | 'competitor.features'
  | 'wbs.priority_for_instance'
  | 'wbs.update_progress';

type AdminHubRequest = {
  action: AdminHubAction;
  params: Record<string, unknown>;
};

Enter fullscreen mode Exit fullscreen mode

TypeScript union types catch misspelled action names at compile time.

CI Enforcement: EF-CAP-50

# .github/workflows/ef-audit.yml
- name: Count Edge Functions
  run: |
    EF_COUNT=$(ls supabase/functions/ | grep -v '_shared' | wc -l)
    echo "EF count: $EF_COUNT"
    if [ "$EF_COUNT" -gt 50 ]; then
      gh issue create \
        --title "EF-CAP-50 violated: $EF_COUNT functions" \
        --body "Add to existing hub instead of creating new EF"
      exit 1
    fi

Enter fullscreen mode Exit fullscreen mode

PRs that push EF count over 50 automatically generate a GitHub Issue and fail CI.

Deny-by-Default: Security Through Explicit Allowlists

A critical piece of the hub pattern: new actions are denied by default.

const ALLOWED_ACTIONS = new Set([
  'competitor.check',
  'competitor.pricing',
  // only explicitly permitted actions work
]);

if (!ALLOWED_ACTIONS.has(action)) {
  return new Response(
    JSON.stringify({ error: 'Action not permitted' }),
    { status: 403 }
  );
}

Enter fullscreen mode Exit fullscreen mode

This is the same principle as MCP server security (principle of least privilege): no action is available unless it's been explicitly reviewed and added.

EF Count Over Time

Phase EF Count Notes
Initial (one-EF-per-feature) 23 Natural growth
After hub migration 15 7 competitor EFs → 1 hub
Today 18 50+ features absorbed as hub actions

Features went from 23 → 50+. EF count went from 23 → 18.

The Mental Model

The hub pattern works because there are two different kinds of boundaries in the system:

  • EF boundaries = domain boundaries (competitor, scheduling, AI, tools)
  • Action boundaries = feature boundaries (check, pricing, features, predict)

EFs grow with domains (which are stable). Actions grow with features (which keep growing). Separate the two, and you stop paying the EF cost for every new feature.

The rule of thumb: if the new feature belongs to an existing domain, add it as an action. Only create a new EF when you're adding an entirely new domain.