l8services

Service Framework

Distributed services with SLA, transactions, and replication.

Overview

L8Services is the core services framework for Layer 8. It provides SLA-based service management, distributed caching, leader election, ACID transactions, Map-Reduce, data import/export, file storage, and replication.

Base Service

Foundation CRUD handler implementing Post, Put, Patch, Delete, and Get. Integrated cache interaction with SLA-based Before/After callbacks. Query support with pagination. Async notification queue with 50,000 capacity.

Distributed Cache

Thread-safe distributed cache with persistent storage backends, property change listeners, paginated fetch, metadata collection, and replication-aware operations.

Service Manager

Central orchestrator handling registration, discovery, request routing, and transaction coordination. Leader election uses the bully algorithm with 3-second election timeout and 5-second heartbeat timeout. Election debouncing (500ms window) prevents storms. Service grouping reduces election traffic by roughly 80%.

Transaction Engine

Six-state machine for ACID 2-phase commit: Create, Queue, Run, Commit (or Rollback), Cleanup. Optimized rollback targets only peers that committed. Proper PreCommit map cleanup.

Map-Reduce

Distributed parallel processing across service nodes. Implement IMapReduceService.Merge() to combine results from all participants. Supports all five actions: MapR_POST, MapR_GET, MapR_PUT, MapR_PATCH, MapR_DELETE.

Data Import

Full import pipeline with four sub-handlers: AI-based field mapping, import execution with validation, model metadata queries, and template transfer/export. Includes heuristic field matching, multi-format file parsing, value transformation, and typed record building.

Additional Components

CSV Export
Stateless export service returning formatted CSV data
File Store
Upload/download with configurable size limits (default 5MB) and storage root
Replication
Tracks which nodes store which data via L8ReplicationIndex
Recovery
Synchronizes data from leader to followers in pages of 500 elements

Architecture

services/base/
CRUD service foundation (5 files, ~470 lines)
services/dcache/
Distributed cache (10 files, ~405 lines)
services/manager/
Service orchestration (10 files, ~1,970 lines)
services/transaction/
ACID transactions (10 files, ~834 lines)
services/dataimport/
Import pipeline (9 files, ~1,265 lines)
services/csvexport/
CSV export (4 files, ~350 lines)
services/filestore/
File storage (5 files, ~330 lines)
services/replication/
Replication tracking
services/recovery/
Data synchronization

Testing

Tests use the l8test framework with a 4-node topology across 3 VNets. Coverage includes base service CRUD, distributed cache, Map-Reduce with 9 participants, transaction coordination, replication, notification delivery, and service manager operations. Roughly 5,900 lines of service code across 55 files, plus 1,500 lines of tests across 12 test files.