اتصل

تصميم SaaS لمزود خدمة إنترنت متعدد المستأجرين: دروس من NexaLink

الصفحة الرئيسية / مدونة

6 دقيقة قراءة
ZILL E ALIمارس 30, 2026NexaLink

إن الحصول على بنية NexaLink ISP SaaS صحيحة يبدأ بقرار واحد: كيفية عزل المستأجرين.

NexaLink هي منصة إدارة مزود خدمة إنترنت: المشتركين، الخطط، الفواتير، القسائم، وأتمتة RouterOS للمشغلين الصغار الذين لا يمكنهم تبرير نظام OSS من فئة الناقل. كان تعدد المستأجرين هو القرار المعماري الأول وهو ما ورثه كل شيء آخر.

مخطط لكل مستأجر. قاعدة بيانات واحدة، مخطط PostgreSQL واحد لكل مزود خدمة إنترنت. عزل قوي، استعادة سهلة لكل مستأجر، ونموذج ذهني مُرضٍ.

مستوى الصف. مجموعة جداول مشتركة، a tenant_id على كل صف، مفروض عالمياً.

تقدم NexaLink بنية مستوى الصف. العامل الحاسم لم يكن الأداء — بل العمليات. مع 200 مستأجر، يعني مخطط لكل مستأجر 200 عملية ترحيل مخطط لكل إصدار، 200 مجموعة من أحواض الاتصال، وفشل ترحيل في المستأجر 147 يترك الأسطول في حالات مختلطة. يجعل مستوى الصف الإصدار ترحيلة واحدة ومسار رجوع واحد.

حيث يبرز مخطط لكل مستأجر: عدد قليل من المستأجرين الكبار الذين يطلبون فصلًا ماديًا، أو حقول مخصصة لكل مستأجر. هذا لم يكن العميل المستهدف.

NexaLink ISP SaaS architecture: row-level multi-tenant isolation with ISP operators, Laravel tenant middleware and PostgreSQL rows scoped by tenant_id

جعل مستوى الصف آمناً

الخطر مع عزل مستوى الصف هو نسيان where tenant_id = ?. ثلاث طبقات توقفه:

  1. سياق المستأجر من الطبقة الوسيطة. يُستخلص من المستخدم المصادق عليه، ولا من مدخلات المستخدم.
  2. نطاق استعلام عالمي على كل نموذج مملوك للمستأجر, يُطبق بواسطة فئة أساسية بحيث لا يمكن لنموذج جديد الانسحاب بالإغفال.
  3. أمان مستوى الصف في PostgreSQL كضمان إضافي، بحيث حتى استعلام خام في مهمة خلفية لا يمكنه عبور المستأجرين.

ثم مجموعة الاختبارات: كل مورد مملوك للمستأجر لديه اختبار يُصادق كالمستأجر A ويتأكد أن طلب سجل المستأجر B يُعيد 404، لا 403. 403 يؤكد وجود السجل — وهذا نفسه تسريب صغير.

استعادة لكل مستأجر في نموذج مستوى الصف

المقايضة الحقيقية لتعدد المستأجرين على مستوى الصف مقابل مخطط لكل مستأجر تظهر عند وقت الاستعادة، لا عند وقت الترحيل. نسخة احتياطية كاملة لقاعدة البيانات تستعيد المنصة بأكملها نظيفة؛ استخراج بيانات مستأجر واحد من تلك النسخة بعد خطأ المشغل — حذف جماعي سيئ للمشتركين، على سبيل المثال — يعني استعادة انتقائية مُحددة على tenant_id عبر كل جدول متأثر، وليس تبديل مخطط واحد.

إجابة NexaLink هي تصدير منطقي مجدول لكل مستأجر (عادي pg_dump مُفلتر حسب المستأجر، مكتوب سكريبتاً بدلاً من النقر) يجلس جنب النسخة الاحتياطية الفيزيائية الكاملة — أبطأ في الإنتاج من استعادة مخطط لكل مستأجر، لكن يعني أن حادثة مشغل واحد لا تتطلب استعادة ثم إعادة تصدير البيانات لكل مستأجر آخر على المنصة فقط لعزل صفوف مستأجر واحد مرة أخرى.

FreeRADIUS في منصة مشتركة

كان مخطط RADIUS هو الجزء المثير للاهتمام. المشتركون من مزودي خدمة إنترنت مختلفين يشاركون radcheck و radacct، وتتصادم أسماء المستخدمين — ali موجود في ثلاث مزودي خدمة إنترنت.

الحل هو اسم مستخدم مؤهل بالمجال: ali@tenant-slug. RouterOS sends it verbatim, FreeRADIUS resolves the tenant from the realm, and accounting rows carry the tenant along for free. Retrofitting this later would have meant reissuing every subscriber credential on the platform, so it is worth deciding on day one.

radacct is the heaviest table by far. It is partitioned by month, with old partitions detached to cold storage after the billing dispute window closes.

Noisy-neighbor tenants in a shared database

Row-level tenancy means every tenant shares the same database connection pool and the same query planner’s attention – a reporting query one operator runs against their own 50,000 subscribers can slow down every other tenant’s dashboard at the same moment, something schema-per-tenant isolation would never expose the platform to. Two things keep this from becoming a recurring incident:

  • A separate read-replica connection for reporting/export queries, never the same connection pool that serves the operator dashboard and the RADIUS-facing API – an expensive analytics query degrading reporting for one tenant is an inconvenience; the same query degrading live PPPoE authentication for every tenant is an outage.
  • Per-tenant query timeouts enforced at the application layer, not left to the database default – a runaway query from one tenant’s bulk CSV export should fail that one request, not queue up behind every other tenant’s traffic.

Automating RouterOS safely

Pushing configuration to customer routers from a SaaS is the feature operators want and the one most likely to cause a bad day.

Rules NexaLink follows:

  • Never push a full configuration. Only additive, scoped commands, each idempotent.
  • Queue every change, with a per-router serial worker. Two concurrent changes to one router is how you get a half-applied firewall.
  • Read back and verify after each change; a job is not complete until the router confirms the resulting state.
  • A dry-run mode that renders the exact commands for the operator to review. Trust is earned by showing your work.
  • A hard stop on rules affecting management access. No automation should be able to lock the operator out of their own router.

The migration I would undo

Early on, invoices stored the plan's price as a foreign key to the plan record instead of copying the amount onto the invoice line. It worked until the first ISP raised prices — and every historical invoice silently re-priced itself. Reconciling six months of already-paid invoices against changed totals was a weekend I will not get back.

Financial records must be immutable snapshots. Copy the price, the tax rate, the plan name, and the currency onto the document at issue time. Reference the plan for reporting if you like, but never for the number the customer paid.

What I would keep

  • Row-level tenancy with enforcement at three layers.
  • Realm-qualified RADIUS usernames from the first commit.
  • Queued, verified, idempotent router automation.
  • Immutable financial documents.
  • Boring, well-understood infrastructure — PostgreSQL, Laravel, Redis — so the interesting problems stay in the ISP domain, not the plumbing.

Onboarding a new ISP tenant without a support ticket

The gap between “sign up” and “actually provisioning subscribers” is where a lot of self-serve SaaS platforms quietly lose tenants to a support queue. NexaLink’s onboarding flow deliberately front-loads three decisions a new ISP has to make before their first voucher is issued, rather than letting them discover each one mid-setup:

  • RADIUS realm slug chosen at signup, not editable later – since it is baked into every subscriber’s username from the first activation, changing it after real customers exist means reissuing credentials, exactly the mistake the realm-qualified username design above was built to avoid repeating.
  • At least one bandwidth plan created before the first voucher can be issued – a platform that lets an operator generate vouchers with no plan attached just moves the error from signup time to the first angry subscriber call.
  • A test RouterOS connection verified during setup, using the same dry-run mode described above, so a credential or firewall mistake surfaces as a setup-screen error instead of a “why isn’t anything working” ticket after the first real voucher is sold.

None of this is complicated individually. The discipline is simply refusing to let a tenant reach “sell your first voucher” with any of these three still undecided.

If you run a small ISP and this stack sounds like what you have been assembling by hand, that is exactly the gap NexaLink exists to close.

كتب بواسطة

ZILL E ALI

مهندس شبكات معتمد بشهادتي MTCNA و MTCRE ومتخصص في بنية تحتية لمزودي خدمة الإنترنت، ومؤسس Developer Zon. يكتب هنا عن MikroTik و Cisco وبنية تحتية لمزودي الخدمة، وأحيانًا عن سجلات البناء.

اترك ردًا

يستخدم هذا الموقع Akismet لتقليل البريد المزعج. تعرف على كيفية معالجة بيانات تعليقك.