← Hub
AltScore Platform · Architecture
Functional
Architecture
DOC-ID: FA-ALTSCORE-001
Version: 1.0 · May 2026
Classification: INTERNAL — Engineering & Product
Owner: Engineering, AltScore Technologies
8 Core Domain Services ERP Ingestion · Feature Pipeline · Scoring · Consent · Score API · Audit · Notifications · Admin
5 External Integration Points Tally Prime · SAP B1 · WhatsApp Business API · NBFC Score API · Distributor Dashboard
3 Async Processing Tiers Real-time (API) · Near-real-time (Kafka) · Batch (Airflow)
01 —

Overview & Principles

AltScore is a data pipeline and ML scoring platform. Its functional architecture separates concerns cleanly across ingestion, transformation, inference, and delivery — enabling each layer to evolve independently while preserving strong data lineage and consent enforcement at every boundary.

FA-ALTSCORE-001 · Architecture Charter

The system is structured around a medallion data lake (Bronze → Silver → Gold) as the single source of truth, with event-driven side-effects for notifications and audit. All cross-service communication uses well-defined contracts; no service reaches directly into another service's data store.

Principle 1

Consent at Every Boundary

No data moves between layers or services without a consent check. The Consent Service is the authority; it is never bypassed.

Principle 2

Pseudonymization at Ingest

PII (GST, phone) is replaced with stable UUIDs at the Bronze→Silver boundary. Downstream services never see raw identifiers.

Principle 3

Immutable Audit Trail

Every score request, consent event, and data access is written to an append-only audit log. Nothing is deleted or updated in the audit store.

Principle 4

Fail-Safe Defaults

On any service failure, the system returns a safe response (block, not allow). No score is served if consent cannot be verified.

Principle 5

Stateless Services

All API-tier services are stateless. State lives in PostgreSQL (transactional), Redis (cache), or the data lake (analytical). Services scale horizontally.

Principle 6

Schema-First Contracts

All inter-service interfaces are defined by OpenAPI schemas or Avro schemas (Kafka topics). No untyped JSON payloads cross service boundaries.

02 —

Domain Decomposition

AltScore decomposes into eight bounded domains, each owned by a specific team. Domains communicate via well-defined APIs or Kafka topics — never by shared database tables.

DomainResponsibilityOwning TeamPrimary StorageKey Consumers
ERP IngestionPull structured data from Tally Prime / SAP B1 / CSV via connector SDK. Validate, quarantine, write to Bronze layer.Data EngineeringS3/ADLS Bronze bucketFeature Pipeline
ConsentManage retailer consent lifecycle (grant, revoke, scope). Single source of truth for all consent decisions.Product EngineeringPostgreSQL (consent_records)Score API, Feature Pipeline, Notifications
Feature PipelineBronze→Silver pseudonymization, Silver feature engineering, Gold score features. Managed by Airflow + Spark + dbt.Data Engineering / MLS3/ADLS Silver + GoldScoring Engine
Scoring EngineLoad features, run XGBoost inference, compute SHAP codes, apply guardrails, write score to Gold store.ML EngineeringPostgreSQL (scores), Redis (cache)Score API
Score APIExternal-facing REST API for NBFC lenders. Auth, consent check, rate limiting, score retrieval, reason code delivery.API EngineeringRedis (cache), PostgreSQL (read)NBFC Partners
Audit & ComplianceAppend-only event logging for all score requests, consent changes, data access, admin actions. 7-year retention.Security / PlatformS3 WORM + PostgreSQL (audit_log)Legal, DPO, SIEM
NotificationsWhatsApp consent flows, score alerts to retailers, grievance acknowledgement. Stateless send-and-forget.Product EngineeringNone (stateless) + Kafka (outbox)Retailers, Distributors
Admin & OperationsInternal dashboard for distributor onboarding, model promotion, grievance management, compliance reports.Ops / EngineeringPostgreSQL (admin_db)Internal Staff
03 —

System Architecture Diagram

External Actors
Tally Prime ERPREST/SDK · mTLS
SAP Business OneREST/SDK · mTLS
CSV UploadSFTP / HTTPS
NBFC LendersScore API · JWT RS256
Retailer (WhatsApp)WhatsApp Business API
Distributor DashboardWeb · OIDC SSO
↓ mTLS / HTTPS / WhatsApp API ↓
Gateway Layer
API GatewayAWS API GW / Kong · TLS 1.3 · Rate Limit · JWT Verify
ERP Connector GatewayFastAPI · mTLS · Payload Signing · Schema Validation
WhatsApp Webhook HandlerFastAPI · HMAC Verify · Idempotent
↓ Internal HTTPS (service mesh) ↓
Core Application Services
Score API ServiceFastAPI · Redis · PostgreSQL RLS
Consent ServiceFastAPI · PostgreSQL · ECDSA Signing
ERP Ingestion ServicePython · Spark · Quarantine Queue
Notification ServiceFastAPI · Kafka Outbox · WhatsApp API
Admin ServiceFastAPI · FIDO2 Auth · PostgreSQL
↓ Kafka Events + Airflow DAGs ↓
ML & Data Pipeline
Feature Pipeline (Airflow)Spark · dbt · Bronze→Silver→Gold
Scoring EngineXGBoost · Croston's · Isolation Forest · SHAP
Guardrail EngineGR-1 through GR-6 · Fail-safe
MLflow RegistryModel versioning · SHA-256 WORM
Storage Layer
S3/ADLS Data LakeBronze · Silver · Gold · WORM
PostgreSQLScores · Consent · Audit · Admin · RLS
Redis ClusterScore Cache · Session · Rate Limit
KafkaEvents · Outbox · Dead-letter
04 —

Service Specifications

Score API ServiceExternal-Facing

The only external-facing service that NBFC lenders call. Validates JWT, checks consent scope, enforces rate limits, retrieves score from cache or triggers synchronous scoring, then returns the AltScore response.

  • Auth: JWT RS256 + per-lender client secret (header)
  • Consent: calls Consent Service on every request (cached 60s)
  • Score source: Redis cache (TTL 4h) → PostgreSQL fallback
  • Rate limit: 100 req/min per lender, 429 on breach
  • Returns: altscore, risk_band, pd, recommended_limit, reason_codes, data_freshness_days, score_version
  • Guardrail GR-3: blocks response if reason_codes missing
FastAPI · Python 3.11 · Redis · PostgreSQL (read replica)
Consent ServiceInternal Authority

Single source of truth for all retailer consent decisions. No other service stores consent state. Signs every consent record with ECDSA P-256 and persists immutably. Exposes synchronous consent-check endpoint consumed by Score API.

  • Endpoints: grant, revoke, check, history, export
  • Signing: ECDSA P-256 on every consent record
  • Revocation: processing halt within 1 hour of request
  • Scope: per-lender named in consent artefact
  • Retention: consent records never deleted (7-year audit)
  • Emits: consent.granted, consent.revoked Kafka events
FastAPI · Python 3.11 · PostgreSQL (primary) · KMS for signing key
ERP Ingestion ServiceData Ingest

Receives structured ERP data from the connector SDK deployed at distributor sites. Validates schema, checks payload HMAC, runs completeness scoring, quarantines malformed records, writes clean records to Bronze layer.

  • Auth: mTLS (per-distributor client cert) + API key
  • Validation: JSON schema enforcement + HMAC verification
  • Quarantine: malformed records → quarantine S3 prefix, alert Ops
  • Completeness: computes data_completeness_score (0–100)
  • Dedup: invoice-level idempotency on invoice_id + distributor_id
  • Emits: ingestion.batch.complete Kafka event (triggers pipeline)
FastAPI · Python 3.11 · Apache Spark · S3/ADLS (Bronze)
Feature PipelineBatch / Async

Orchestrated by Airflow. Runs Bronze → Silver (pseudonymization + normalization) and Silver → Gold (feature engineering) transformations on a nightly schedule or triggered by ingestion events.

  • Bronze→Silver: GST/phone pseudonymization, schema normalization, outlier capping
  • Silver→Gold: 40+ feature computation via dbt + Spark
  • Deterministic: same inputs always produce same features
  • Lineage: dbt docs track every transformation step
  • SLA: Gold layer updated within 4 hours of ingestion event
  • Emits: pipeline.gold.ready Kafka event → Scoring Engine
Apache Airflow · Apache Spark · dbt Core · S3/ADLS
Scoring EngineML Core

Triggered by pipeline.gold.ready events. Loads retailer features from Gold layer, routes to correct model (primary XGBoost or Croston's), applies Isolation Forest anomaly check, computes SHAP reason codes, runs guardrails GR-1 through GR-6, writes final score to Gold store.

  • Model loading: from MLflow registry (SHA-256 verified)
  • Routing: 6-month threshold → XGBoost vs. cold-start fallback
  • Guardrails: hard-coded fail-safe per GRD-ALTSCORE-001
  • Score write: PostgreSQL + Redis cache invalidation
  • SHAP: TreeExplainer on every scored retailer
  • Emits: score.computed, score.blocked Kafka events
Python 3.11 · XGBoost 1.7 · SHAP · Isolation Forest · MLflow
Notification ServiceAsync / Outbox

Consumes Kafka events and sends WhatsApp messages to retailers for consent flows, score alerts, and grievance responses. Uses outbox pattern to guarantee at-least-once delivery. Stateless — no notifications stored long-term.

  • Triggers: consent.invite, grievance.ack, score.ready (opt-in)
  • Channel: WhatsApp Business API (primary), SMS fallback
  • Outbox: Kafka → outbox table → delivery confirmation
  • Idempotency: dedup on message_id to prevent duplicate sends
  • Language: Hindi + English templates (all 24 reason code translations)
  • No PII in message payloads beyond what retailer consented to receive
FastAPI · Python 3.11 · Kafka Consumer · WhatsApp Business API
Audit & Compliance ServiceCross-Cutting

Receives audit events from all other services via Kafka. Writes append-only records to PostgreSQL audit_log and replicates to S3 WORM for 7-year retention. Exposes read-only query API for legal/compliance access.

  • Events: score_requested, consent_granted/revoked, erp_ingested, admin_data_access, failed_auth, model_promoted, grievance_filed
  • Immutable: no UPDATE or DELETE on audit_log table (enforced at DB level)
  • WORM: daily export to S3 Object Lock for long-term retention
  • Query API: read-only, FIDO2-authenticated, for Legal/DPO use
  • SIEM: streams to external SIEM via Kafka connector
FastAPI · Python 3.11 · PostgreSQL (audit) · S3 Object Lock
Admin ServiceInternal Only

Internal-only service for distributor onboarding, NBFC partner management, model promotion workflow, grievance case management, and compliance reporting. Requires FIDO2 hardware key + SSO for all access.

  • Auth: FIDO2 WebAuthn + SAML 2.0 SSO (no passwords)
  • RBAC: 7 roles from SAR-ALTSCORE-001 matrix
  • Model promotion: two-person sign-off workflow
  • Grievance: SLA tracking, escalation triggers
  • Distributor onboarding: cert issuance, API key generation
  • All admin actions emitted to Audit Service
FastAPI · Python 3.11 · PostgreSQL · React admin UI
05 —

Primary Data Flows

Flow A: ERP Ingestion to Score

1

ERP Connector Sync

Distributor's Tally Prime or SAP B1 connector SDK calls ERP Ingestion Service (POST /v1/ingest/batch) over mTLS. Payload is HMAC-signed with distributor's API key. Service validates schema, runs completeness scoring, deduplicates on invoice_id, writes clean records to Bronze S3 prefix.

2

Ingestion Event Published

ERP Ingestion Service emits ingestion.batch.complete to Kafka topic with distributor_id, batch_id, record_count, completeness_score. Airflow DAG subscribes via sensor.

3

Feature Pipeline Runs

Airflow triggers Bronze→Silver DAG: pseudonymizes GST/phone to UUIDs, normalizes schema across ERP types, applies outlier caps. Then triggers Silver→Gold DAG: computes all 40+ features via dbt + Spark. Lineage recorded in dbt docs.

4

Consent Verified Before Scoring

Before scoring a retailer, Scoring Engine calls Consent Service to verify active consent. If no consent or revoked: score is not computed; score.blocked event emitted; retailer flagged for consent outreach.

5

Model Inference + Guardrails

Scoring Engine loads features from Gold layer, routes to XGBoost or cold-start fallback, runs Isolation Forest anomaly check (GR-2), computes SHAP reason codes (GR-3), applies affordability ceiling (GR-4), validates data quality score (GR-5). Score written to PostgreSQL + Redis cache.

6

Score Available for API

score.computed event emitted to Kafka. Score API Service cache is invalidated and populated with fresh score (TTL 4 hours). NBFC lender's next API call returns fresh result within p95 < 2s.

Flow B: NBFC Score API Request

1

Lender Calls Score API

POST /v1/score with JWT RS256 bearer token + retailer_id. API Gateway validates JWT signature, enforces rate limit (100 req/min). Request forwarded to Score API Service.

2

Consent Scope Check

Score API Service calls Consent Service: does the requesting lender appear in the retailer's active consent scope? If not → 403 Forbidden. Consent check result cached per (retailer_id, lender_id) for 60 seconds.

3

Score Retrieval

Check Redis cache for retailer_id. Cache hit: return immediately (p50 <100ms). Cache miss: query PostgreSQL score store (p95 <500ms). If score older than 24h: return score with data_freshness_days warning. No score exists: return 404.

4

Audit Event Written

Every Score API call — hit, miss, or blocked — emits score_requested audit event to Kafka → Audit Service (async, non-blocking). Audit write failure does not block API response but triggers alerting.

Flow C: Consent Grant (WhatsApp)

1

Distributor Initiates

Distributor sends consent invite from dashboard. Admin Service calls Notification Service: send WhatsApp invite to retailer's phone with distributor name, purpose, and rights summary.

2

Retailer Affirms

Retailer responds "HAAN" (Yes) to WhatsApp message. WhatsApp webhook delivers message to Webhook Handler. Handler parses retailer_id, validates HMAC, calls Consent Service POST /v1/consent/grant.

3

Consent Record Created

Consent Service creates ECDSA P-256 signed consent record with retailer_id (UUID), purpose, lender_scope[], expiry, timestamp. Emits consent.granted Kafka event. Notification Service sends confirmation WhatsApp to retailer.

06 —

Inter-Service Interfaces

FromToProtocolContractAuthNotes
NBFC LenderScore API ServiceHTTPS RESTOpenAPI 3.1 (API-ALTSCORE-001)JWT RS256Rate-limited; audit on every call
ERP Connector SDKERP Ingestion ServiceHTTPS RESTOpenAPI 3.1 (ERP schema)mTLS + API keyHMAC payload signing required
WhatsApp WebhookWebhook HandlerHTTPS POSTMeta Webhook formatHMAC-SHA256Idempotent on message_id
Score API ServiceConsent ServiceInternal HTTPSOpenAPI (internal)mTLS service identity60s consent cache on caller side
Scoring EngineConsent ServiceInternal HTTPSOpenAPI (internal)mTLS service identityBlocks scoring if no consent
ERP IngestionFeature PipelineKafkaAvro: ingestion.batch.completeSASL/SCRAMAirflow sensor consumes
Feature PipelineScoring EngineKafkaAvro: pipeline.gold.readySASL/SCRAMTriggers batch scoring run
All servicesAudit ServiceKafkaAvro: audit_event schemaSASL/SCRAMFire-and-forget; DLQ on failure
Consent ServiceNotification ServiceKafkaAvro: consent.granted / revokedSASL/SCRAMTriggers WhatsApp confirmation
Scoring EngineNotification ServiceKafkaAvro: score.computedSASL/SCRAMOptional retailer score-ready alert
Admin ServiceAll ServicesInternal HTTPSOpenAPI (internal admin)FIDO2 + SSO tokenAll admin actions audit-logged
07 —

Event Catalogue

All asynchronous communication uses Kafka with Avro-schema topics. Every event schema is versioned in the schema registry. Consumers must handle at-least-once delivery via idempotent processing.

EventTopicProducerConsumersRetention
ingestion.batch.completealtscore.ingestionERP Ingestion ServiceFeature Pipeline (Airflow sensor)7 days
pipeline.gold.readyaltscore.pipelineFeature PipelineScoring Engine7 days
score.computedaltscore.scoresScoring EngineNotification Service, Score API (cache invalidation)30 days
score.blockedaltscore.scoresScoring Engine / GuardrailsAudit Service, Notification Service30 days
consent.grantedaltscore.consentConsent ServiceNotification Service, Audit Service, Feature PipelineIndefinite
consent.revokedaltscore.consentConsent ServiceScoring Engine (halt), Score API (invalidate), Audit ServiceIndefinite
audit_eventaltscore.auditAll servicesAudit Service7 years (S3 WORM)
grievance.filedaltscore.grievancesScore API ServiceAudit Service, Admin Service (SLA timer), Notification Service7 years
model.promotedaltscore.mlAdmin ServiceScoring Engine (reload), Audit ServiceIndefinite
erp.anomaly.detectedaltscore.anomalyScoring Engine (Isolation Forest)Audit Service, Admin Service90 days
08 —

Error Handling & Resilience

Failure ScenarioSystem BehaviourRecovery Path
Consent Service unreachableScore API returns 503; score blocked (fail-safe). Redis consent cache (60s) absorbs brief outages.Auto-retry 3× with backoff; circuit breaker opens at 50% failure rate
ERP Ingestion schema mismatchRecord quarantined to S3 quarantine prefix; batch continues for valid records; alert sent to OpsOps reviews quarantine, distributor SDK updated, records reprocessed
Airflow pipeline DAG failureFeature Pipeline retries 3×; Gold layer not updated; Scoring Engine uses existing cached score with staleness flagOn-call engineer notified; manual DAG re-trigger via Admin Service
Scoring Engine model load failureScore computation blocked; score.blocked event emitted; previous cached score served with warningMLflow registry check; model artifact re-downloaded; SHA-256 re-verified
Redis cache failureScore API falls back to PostgreSQL read replica; latency degrades but service remains availableRedis cluster auto-failover (Sentinel); cache warming on recovery
Kafka broker unavailableServices use local transactional outbox; events queued locally and replayed on reconnectKafka auto-recovery; outbox drain; dead-letter queue for failed events
WhatsApp API downtimeNotification Service queues messages in outbox; retries with exponential backoff up to 24hSMS fallback triggered after 30-min WhatsApp outage
SHAP computation failureGuardrail GR-3: score blocked entirely. No score without reason codes (RBI FLDG). score.blocked emitted.ML engineer investigation; model re-run triggered once resolved
09 —

Non-Functional Requirements

Performance Targets

Operationp50p95p99
Score API (cache hit)<100ms<300ms<500ms
Score API (cache miss)<500ms<2s<3s
Consent check<50ms<200ms<400ms
ERP batch ingest (10K records)<30s<90s<5min
Feature pipeline (full run)<4h<6h
Scoring (1K retailers)<30min<1h

Availability & Scalability

DimensionTarget
Score API uptime99.9% monthly
Consent Service uptime99.95% (critical path)
Concurrent lenders50 simultaneous at 100 req/min each
Max retailers scored500K per nightly batch
ERP batches/day1,000+ distributor syncs
Horizontal scalingAll API services auto-scale on CPU >70%
10 —

Architectural Constraints

The following constraints are non-negotiable. Any proposed change to the architecture that would violate these requires explicit sign-off from the Head of Engineering + DPO + Head of Risk.

#ConstraintRationaleOwner
C-01No PII (GST, phone) may cross the Bronze→Silver boundary in raw formDPDP Act 2023; privacy-by-designDPO
C-02Consent must be verified on every Score API call; no bypassDPDP Act; fail-safe designDPO + Engineering
C-03All data must remain in India-region cloud infrastructureDPDP Act data localisation; RBI guidelinesDPO + CISO
C-04Guardrail thresholds are compile-time constants, not runtime configGRD-ALTSCORE-001; tamper-resistanceHead of Risk + ML
C-05Audit log records may never be updated or deletedLegal hold; DPDP; RBICISO + Legal
C-06Model artifacts must be SHA-256 verified before loadingML supply-chain integrity; TM-ML-04ML Engineering
C-07Score API must not expose sequential retailer IDs (IDOR risk)TM-API-01; privacySecurity + API Engineering
C-08No service may directly query another service's databaseDomain isolation; reduces blast radiusHead of Engineering