Skip to content

Adapter Technical Requirements

This defines the technical requirements for the Adapter layer, which connects the ports defined in the application business requirements to actual technical implementations. This layer implements the interfaces defined by the domain/application layers and handles integration with external systems.

The key differentiator of this example is the practical application of LanguageExt IO advanced features (Timeout, Retry, Fork, Bracket). It solves network latency, intermittent failures, timeouts, and resource management issues that arise when integrating with external services in a functional manner.

Core characteristics of the 4 advanced IO features:

IO PatternProblem ScenarioGuaranteeFunctorium Integration
Timeout + CatchSlow responses degrade the entire systemLimits maximum wait time + converts timeout to fallbackIO.Timeout() -> .Catch(TimedOut) -> .Catch(Exceptional)
Retry + ScheduleIntermittent 503/network errorsAutomatic recovery with exponential backoff + jitterIO.Retry(exponential | jitter | recurs | maxDelay)
Fork + awaitAllSequential execution bottleneck for N independent tasksParallel execution, worst-case time = max(individual times)forks.Map(io => io.Fork()) -> awaitAll(forks)
BracketResource (session, connection) leaks on exceptionsAcquire-Use-Release lifecycle guaranteeacquire.Bracket(Use: ..., Fin: ...)

The persistence layer for storing and retrieving data.

  • Provides InMemory implementation as default
  • Designed to support switching to Sqlite (EF Core/Dapper) implementation
  • Selects the implementation via configuration file (Persistence:Provider)
  • Implements 4 Repository interfaces: IAIModelRepository, IDeploymentRepository, IAssessmentRepository, IIncidentRepository
  • Implements 5 Query ports: IAIModelQuery, IModelDetailQuery, IDeploymentQuery, IDeploymentDetailQuery, IIncidentQuery
  • Supports the UnitOfWork pattern
  • Registers Source Generator-generated Observable wrappers in DI

The service layer integrating with external AI platforms. Each service demonstrates a specific pattern of LanguageExt IO advanced features.

  • Checks the health status of deployed models
  • Applies a 10-second timeout
  • Returns a TimedOut fallback result instead of failure on timeout
  • Converts exceptions to AdapterError
  • Retrieves drift reports for deployed models
  • On intermittent failure, retries with exponential backoff (100ms base) + jitter (0.3) + max 3 retries
  • Applies a maximum delay of 5 seconds
  • Converts to AdapterError on final failure

2-3. Parallel Compliance Check (Fork + awaitAll)

Section titled “2-3. Parallel Compliance Check (Fork + awaitAll)”
  • Checks 5 compliance criteria in parallel: DataGovernance, SecurityReview, BiasAssessment, TransparencyAudit, HumanOversight
  • Each criterion check is Forked as an independent IO operation
  • Collects all results via awaitAll
  • Aggregates whether all criteria passed
  • Looks up model metadata from an external registry
  • Acquire -> Use -> Release the registry session
  • Session release is guaranteed regardless of success/failure
  • Converts exceptions to AdapterError

Provides a REST API based on FastEndpoints.

  • Model management: registration, lookup, search, risk classification (4 endpoints)
  • Deployment management: creation, lookup, search, review submission, activation, quarantine (6 endpoints)
  • Assessment management: initiation, lookup (2 endpoints)
  • Incident management: reporting, lookup, search (3 endpoints)
  • Supports FinResponse -> HTTP status code conversion

Provides OpenTelemetry 3-Pillar observability.

  • Auto-generates logging/metrics/tracing via [GenerateObservablePort] Source Generator
  • Provides event publishing observability via ObservableDomainEventNotificationPublisher
  • Auto-registers Pipeline middleware (Validation, Logging)
  1. Health check success — Receives a response within 10 seconds and returns a Healthy/Degraded result.
  2. Health check timeout — Returns a TimedOut fallback result when exceeding 10 seconds (not an error).
  3. Monitoring retry success — Receives the drift report via retry after initial failure.
  4. Parallel check completion — 5 criteria execute in parallel, completing faster than sequential execution.
  5. Registry session normal release — Session is normally released after successful lookup.
  6. Registry session release after error — Session is released even if the lookup fails (Bracket guarantee).
  1. Monitoring final failure — Returns a MonitoringFailed error if still failing after 3 retries.
  2. Parallel check partial failure — Returns a ComplianceCheckFailed error if some criterion checks fail.
  3. Session acquisition failure — Returns a RegistryLookupFailed error if registry session acquisition fails.

In the next step, we analyze these technical requirements and derive the IO pattern selection rationale in Type Design Decisions.