1 agents

scalability-architect

scalability-architect

Overview

The Scalability Architect is an L3 agent operating in the architecture domain of the Prismatic Platform. This agent specializes in designing and enforcing horizontal and vertical scaling strategies, load balancing configurations, and capacity planning models that ensure the platform can handle increasing workloads without degradation in performance or reliability.

Built on the BEAM virtual machine's inherent concurrency capabilities, the Scalability Architect leverages OTP design patterns to create systems that scale naturally through process multiplication rather than requiring fundamental architectural changes. The agent continuously monitors resource utilization patterns, identifies bottlenecks before they impact users, and recommends or autonomously applies scaling adjustments within its authority boundaries.

As part of the platform's 434-strong autonomous agent ecosystem, the Scalability Architect contributes to the self-evolving infrastructure by ensuring that architectural decisions made today do not become tomorrow's scalability constraints. Every scaling recommendation passes through the Trinity Gate verification framework before implementation, guaranteeing that improvements are evidence-based and formally validated.

Scaling Strategy Framework

The Scalability Architect operates with a comprehensive framework that addresses scaling at multiple levels of the system architecture.

StrategyTypeMechanismUse Case
Process MultiplicationHorizontalSpawn additional worker processesCPU-bound workloads
Node DistributionHorizontalDistribute across BEAM nodesGeographic scaling
ETS PartitioningHorizontalShard ETS tables across processesRead-heavy data
Connection PoolingVerticalOptimize connection poolsDatabase connections
GenStage BackpressureVerticalApply backpressure to pipelinesStream processing
Cache TieringHybridMulti-level caching with evictionLatency-sensitive paths
Supervision PartitioningHorizontalSplit supervision treesFault isolation

Horizontal Scaling Architecture

The platform's umbrella application architecture naturally supports horizontal scaling because each application within the umbrella can be deployed independently or co-located based on resource requirements.

defmodule PrismaticAgents.ScalabilityArchitect do
  @moduledoc """
  L3 Scalability Architect agent.
  Designs and enforces horizontal/vertical scaling strategies.
  """

  use GenServer
  require Logger

  @analysis_interval_ms :timer.minutes(5)

  defstruct [
    :cluster_topology,
    :resource_snapshot,
    :scaling_recommendations,
    :last_analysis_at,
    status: :monitoring
  ]

  @spec start_link(keyword()) :: GenServer.on_start()
  def start_link(opts \\ []) do
    GenServer.start_link(__MODULE__, opts, name: __MODULE__)
  end

  @impl true
  def init(_opts) do
    schedule_analysis()
    {:ok, %__MODULE__{cluster_topology: discover_topology()}}
  end

  @impl true
  def handle_info(:analyze, state) do
    snapshot = capture_resource_snapshot()
    recommendations = analyze_scaling_needs(snapshot, state.cluster_topology)

    :telemetry.execute(
      [:prismatic, :agents, :scalability, :analysis_complete],
      %{recommendation_count: length(recommendations)},
      %{topology: state.cluster_topology}
    )

    schedule_analysis()

    {:noreply, %{state |
      resource_snapshot: snapshot,
      scaling_recommendations: recommendations,
      last_analysis_at: DateTime.utc_now()
    }}
  end

  defp discover_topology do
    %{
      nodes: Node.list([:this, :visible]),
      schedulers: System.schedulers_online(),
      memory_mb: :erlang.memory(:total) |> div(1_048_576)
    }
  end

  defp capture_resource_snapshot do
    %{
      process_count: :erlang.system_info(:process_count),
      run_queue: :erlang.statistics(:run_queue),
      memory: :erlang.memory(),
      io: :erlang.statistics(:io),
      scheduler_utilization: :scheduler.utilization(1)
    }
  end
end

Vertical Scaling Optimization

Vertical scaling within the BEAM involves optimizing resource usage within a single node. The Scalability Architect monitors several key metrics to identify vertical scaling opportunities.

Memory Optimization Targets

ComponentOptimizationExpected Impact
ETS tablesCompress large tables, tune read/write concurrency20-40% memory reduction
Process heapsIdentify processes with oversized heaps15-30% memory reduction
Binary referencesDetect binary reference leaksPrevents OOM crashes
Atom tableMonitor atom creation ratePrevents atom table exhaustion
Mailbox sizesAlert on growing mailboxesPrevents process starvation

Scheduler Utilization

The BEAM scheduler is the foundation of the platform's concurrency model. The Scalability Architect continuously monitors scheduler utilization to detect imbalances that indicate suboptimal workload distribution.

defmodule PrismaticAgents.ScalabilityArchitect.SchedulerAnalysis do
  @moduledoc """
  Scheduler utilization analysis for vertical scaling decisions.
  """

  @spec analyze_scheduler_balance(list()) :: {:balanced | :imbalanced, map()}
  def analyze_scheduler_balance(utilization_samples) do
    avg = Enum.map(utilization_samples, & &1.utilization) |> mean()
    std_dev = Enum.map(utilization_samples, & &1.utilization) |> standard_deviation()

    status = if std_dev / max(avg, 0.01) < 0.15, do: :balanced, else: :imbalanced

    {status, %{
      average_utilization: avg,
      standard_deviation: std_dev,
      coefficient_of_variation: std_dev / max(avg, 0.01),
      recommendation: recommend_action(status, avg)
    }}
  end

  defp recommend_action(:balanced, avg) when avg > 0.85, do: :add_schedulers
  defp recommend_action(:balanced, avg) when avg < 0.20, do: :reduce_schedulers
  defp recommend_action(:imbalanced, _avg), do: :rebalance_workload
  defp recommend_action(:balanced, _avg), do: :no_action
end

Capacity Planning Model

The Scalability Architect maintains a capacity planning model that projects resource requirements based on historical growth patterns and anticipated feature additions.

Planning HorizonData SourceConfidence LevelUpdate Frequency
1 weekReal-time telemetryHigh (>0.95)Continuous
1 monthAggregated metricsMedium (>0.80)Daily
3 monthsTrend analysisMedium (>0.70)Weekly
6 monthsGrowth modelingLow-Medium (>0.60)Bi-weekly
1 yearStrategic projectionsLow (>0.50)Monthly

Load Balancing Configuration

The agent manages load balancing at multiple layers of the architecture. Each layer uses a strategy optimized for its specific traffic characteristics and reliability requirements.

LayerStrategyImplementationFailover
HTTPRound-robin with health checksFly.io edge routingAutomatic region failover
WebSocketSticky sessions for LiveViewPhoenix PubSub affinitySession migration
DatabaseRead replicas with write routingEcto multi-repoAutomatic promotion
Background JobsWork stealing across nodesGenStage demand-drivenRe-queue on failure
Agent TasksCapability-based routingAIAD agent registryAgent pool failover

Cluster Topology Management

The Scalability Architect manages the platform's cluster topology, determining how BEAM nodes are organized, connected, and scaled across the deployment infrastructure. In production, the platform runs on Fly.io with automatic geographic distribution capabilities.

defmodule PrismaticAgents.ScalabilityArchitect.ClusterManager do
  @moduledoc """
  Cluster topology management for multi-node BEAM deployments.
  Monitors node health and manages cluster membership.
  """

  @spec assess_cluster_health() :: {:ok, map()}
  def assess_cluster_health do
    nodes = [Node.self() | Node.list()]

    health = Enum.map(nodes, fn node ->
      {node, %{
        connected: Node.ping(node) == :pong,
        process_count: :rpc.call(node, :erlang, :system_info, [:process_count]),
        memory_mb: div(:rpc.call(node, :erlang, :memory, [:total]), 1_048_576),
        uptime_hours: div(:rpc.call(node, :erlang, :statistics, [:wall_clock]) |> elem(0), 3_600_000)
      }}
    end)

    {:ok, %{
      node_count: length(nodes),
      all_connected: Enum.all?(health, fn {_, h} -> h.connected end),
      total_processes: Enum.sum(Enum.map(health, fn {_, h} -> h.process_count end)),
      total_memory_mb: Enum.sum(Enum.map(health, fn {_, h} -> h.memory_mb end)),
      per_node: Map.new(health)
    }}
  end
end
Topology AspectDevelopmentStagingProduction
Node Count123-6
DistributionLocal onlySingle regionMulti-region
Node DiscoveryManualDNS-basedlibcluster (Fly.io)
State ReplicationNoneHorde (2 replicas)Horde (3 replicas)
FailoverSupervisor restartAutomatic node restartAutomatic + geographic failover

Scaling Decision Framework

The Scalability Architect does not apply scaling changes arbitrarily. Every scaling decision follows a rigorous framework that requires evidence-based justification and formal verification through the Trinity Gate.

Decision CriteriaThresholdActionVerification
CPU SaturationScheduler utilization > 85% sustained 5 minAdd schedulers or nodesPerformance benchmark
Memory PressureTotal memory > 80% of availableAdd memory or optimizeMemory profiling report
Process Count> 500,000 processes per nodeDistribute across nodesProcess audit
Mailbox GrowthAny process mailbox > 10,000 messagesInvestigate bottleneckTargeted profiling
Request LatencyP95 > 200ms for 5 minutesScale horizontallyLoad test verification
Database PoolPool utilization > 90%Increase pool or add replicaConnection audit

Integration Points

The Scalability Architect integrates with the broader platform infrastructure to ensure scaling decisions are coordinated and consistent.

AIAD Specification Compliance

AIAD ComponentStatus
Agent specification fileCompliant
Behavioral rules15 rules defined
Telemetry integrationFull coverage
NM/ND doctrine enforcementActive
Property-based testing38 properties verified
SEADF integrationRegistered

Agents in the architecture domain collaborate to ensure the platform's technical foundations remain sound under growing demands.

Authority Level

L3 - Strategic Command - Multi-domain coordination with authority to recommend and enforce scaling policies across umbrella applications.


Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL