Skip to main content

Email8:Gate - Business Requirements & Functionality

Audience: product owners, business analysts, and anyone evaluating what Email8:Gate does for the business. For architecture read README.md; for wire-level detail read DESIGN.md.

1. Business Purpose​

Email8:Gate is the front door for the mail Internet: it delivers:

  • Stable, well-known ports - mail clients and foreign MX servers connect to TCP 25, 465, 587, 143, 993, 110, 995, and 4190. Those numbers are load-bearing business expectations baked into every RFC client implementation and every MX record on earth; the Gate keeps them fixed while everything behind it moves.
  • Zero-downtime mail operations - mail must keep flowing while the platform upgrades services behind the door; the Gate re-dials healthy instances by the second, so rolling upgrades are invisible to clients.
  • Protocol transparency with a real client address - backend services still see the true client IP/port via PROXY protocol v2, so rate limiting, greylisting, and abuse controls work as if clients connected directly.
  • One door per host - a single listener set per node eliminates port-collision fights among replicas and keeps firewall rules and DNS hygiene trivially correct.

2. Business Scope (What the Service Provides)​

#Capability areaWhat the business gets
1Well-known port listeners25 (SMTP/MX), 465 (SMTPS), 587 (submission), 143 (IMAP), 993 (IMAPS), 110 (POP3), 995 (POP3S), 4190 (Sieve) bound once per host
2Instance discoveryMaps each listener to live healthy MTA/Access instances from the fleet registry (1s cache)
3Byte passthroughBidirectional, protocol-transparent stream forwarding
4Client identity passthroughPROXY v2 headers so backends rate-limit and greylist on the real client address
5Fleet resilienceUpstream eviction on failed connects, retry-to-next-instance, stale-cache tolerance during registry refresh gaps
6Connection governancePer-listener concurrent-connection caps with backpressure (overload sheds excess connections)
7Zero-downtime upgradesSO_REUSEPORT reuse for gate restarts; stop-first upgrade policy for full swaps
8Traffic telemetryConnection/byte/unavailable counters exposed for ops dashboards
9Admin consolegate admin page (listener table + counters) rendered remotely in the platform dashboard
10HealthService health endpoint for fleet supervision

What the service does NOT own (business boundary):

Out of scopeOwned by
SMTP dialogue, spam checks, queueing, deliveryEmail8:Mta
IMAP/POP3/Sieve/DAV protocol sessionsEmail8:Access
Mail dataEmail8:Store / Sentin8:Storage
TLS certificate issuance/rotationSentin8:Acme (implicit-TLS is terminated at the owning service through listener config)
Authorization decisions on protocol trafficShield inside Mta/Access - the Gate performs no policy evaluation of mail traffic
Event transport, scheduling, storage infraSentin8:Bus, Sentin8:Cron, Sentin8:Storage (platform)
External DNS records (MX/SPF/autodiscover)The tenant's DNS + platform provisioning flows

3. Business Capabilities​

3.1 Port ownership​

CapabilityBusiness rule
Bind well-known portsThe Gate is the ONLY mail listener on 25/465/587/143/993/110/995/4190 on a fleet node; one authoritative door avoids collisions and misconfiguration
Listener disablingAn unset port env removes that listener from the door (e.g. sites that front the Gate with their own edge)
Reuse-port restartsOptional SO_REUSEPORT lets a new Gate binary take over connections mid-life for self-upgrades

3.2 Routing the stream​

CapabilityBusiness rule
Service mappingsmtp/submission/submissions → Mta; imap/imaps/pop3/pop3s/sieve → Access (catalog-declared)
Instance selectionRound-robin across Active instances with health freshness ≤30s; deterministic ordering keeps distribution stable
Live bindsBackend instances publish their actual (ephemeral) bound ports; the Gate dials the published port, falling back to the catalog's raw port
Failure handlingFailed dials evict the instance and retry up to 3 attempts across other instances; when all are down, the connection is refused cleanly
Stale toleranceIf a registry refresh returns nothing, the previous healthy set is retained briefly rather than dropping traffic

3.3 Client identity & protection​

CapabilityBusiness rule
PROXY v2 prependThe Gate speaks PROXY protocol v2 to backends (default on), carrying real client IP/port; backends consume it before any protocol bytes
Byte countersConnections, bytes in/out, active sessions, upstream-unavailable events are counted per listener for ops visibility
Overload sheddingConcurrent-connection semaphore (default 2048) refuses excess with a clean disconnect instead of queue collapse

3.4 Observability and admin​

CapabilityBusiness rule
Telemetry snapshotGET /v1/gate/telemetry exposes counters for probing
Admin pageThe gate SDUI page lists live listeners (name/port/upstream) and counters, gated on email8:gate:telemetry:read

4. Business Events (Outbound)​

Email8:Gate publishes no domain events - it never parses mail, and traffic metrics ride the telemetry counters instead. The Shield hot-reload consumer rides the service's -policy workload, and the audit journal drains to the platform audit API.

ChannelContent
Metricsconnections_total, bytes_in/out_total, active_connections, upstream_unavailable_total via the telemetry snapshot / admin page
Audit journal → Sentin8:Sys POST /v1/auditOperational audit only (the leaf journal is drained by the shell pusher)

Inbound (consumed): none.

5. Business Rules & Invariants​

  1. One door per host: unless reuse-port is explicitly enabled, the Gate holds each well-known port exclusively - two Gates on one node would mean undefined mail routing.
  2. The Gate never interprets mail bytes: it cannot alter, drop, or slow-track protocol content - all mail behavior belongs to Mta and Access; the Gate's influence is limited to connection acceptance and dial targets.
  3. Client IP fidelity: backend services always receive the real client address (PROXY v2); abuse controls are never blinded by the passthrough.
  4. Unavailable upstreams fail fast: a connection with no healthy backend is refused at the door within seconds - clients get a clean failure, not a hang.
  5. Registry truth: dial targets come only from the fleet registry plus published listener maps - never from hardcoded endpoints.
  6. No mail data touch: the Gate has no database, no blob access, no secrets beyond its Valkey identity - a compromised Gate cannot read mail.

6. Target-User Roles & Use Cases​

PersonaWhat they do with Email8:Gate
Internet senders / other MTA operatorsConnect to :25 to hand off mail for hosted domains
End users' mail clientsConnect to :993/:143 (IMAP), :587/:465 (submission), :110/:995 (POP3)
Sieve users' clientsConnect to :4190 to manage server-side filters
Email administratorsWatch the gate dashboard page to confirm listeners and traffic
Platform operatorsPerform rolling upgrades relying on instance eviction/re-dial and telemetry counters
Security operationsRely on PROXY v2 so per-IP blocking/greylisting upstream is accurate

7. KPIs / Success Criteria​

CategoryTarget
AvailabilityMail ports remain accepted through backend rolling upgrades; failed upstreams re-dialed within one attempt triple
LatencyPassthrough overhead negligible (bytes forwarded, not parsed); connect-to-backend dial typically same-host/LAN
Correctness100% of backends receive a valid PROXY v2 header before protocol bytes
Overload behaviorConnection cap enforced deterministically; counters reflect refused connections (upstream_unavailable)
AuditabilityListener health and traffic counters are always available for incident response

8. Dependencies & Reliance on Other Services​

Relied onFor
Email8:MtaUpstream for smtp/submission/submissions listeners
Email8:AccessUpstream for imap/imaps/pop3/pop3s/sieve listeners
Valkey (fleet registry)Service-instance status/health and published listener maps (cert-identity ACL)
Sentin8:Acme / platform TLSCertificate material consumed by implicit-TLS backend listeners
Shield (Sentin8:Policy)Admin-page authorization and the telemetry-read policy set
Sentin8:SysAudit journal drain
Sentin8:Cron / Sentin8:BusNot used - Gate is stateless and has no queue/event surface

9. Acceptance Criteria​

  1. Every advertised listener binds its well-known port and forwards to at least one healthy instance of the mapped service.
  2. Killing all instances of a backend stops new connections on those listeners cleanly (refused, counted) and recovers the moment an instance goes Active again.
  3. A rolling upgrade-instance of Mta or Access causes no client handshake failures beyond in-flight connection handling - new dials target the new instances immediately.
  4. Every backend stream begins with a correctly formed PROXY v2 header (unit-tested byte layout, mixed-family handled).
  5. The gate admin page reflects live listeners and counters; access to it requires the telemetry-read scope.
  6. Disabling a listener via env truly frees the port after restart.
  7. make build, make test, make lint pass; the OpenAPI spec matches implemented routes.

10. Open Business Questions​

  • Whether an SMTP-level (PROXY-v2-independent) IP allowlist belongs at the Gate edge for hostile-network scenarios, or should remain at Mta layer where context is richer.
  • TLS termination at the Gate itself (today implicit-TLS is terminated in the backend services; a terminate-at-Gate mode would centralize certificate management).

Architecture & Design: email8:gate and its underlying concepts were designed by Hamid Jahanzad.