What is the CSP Service?
The CSP Service is a Java-based microservice that wraps the Choco constraint solver to perform rigorous mathematical validation and analysis of SaaS pricing models. It’s the engine behind the platform’s ability to verify pricing consistency, enumerate valid configurations, and detect logical errors in complex pricing structures.The CSP Service is based on Choco Solver 4.0.9, a powerful open-source Java library for Constraint Programming.
Architecture Position
The CSP Service sits at the core of the pricing analysis pipeline: The Analysis API (Node.js/TypeScript) delegates all constraint satisfaction operations to the CSP Service, which encodes pricing models as constraint satisfaction problems and solves them using Choco.Key Capabilities
The CSP Service provides several critical capabilities for pricing intelligence:1. Model Validation
Validates the mathematical consistency of a pricing model by:- Ensuring all plans have at least one feature enabled
- Verifying add-ons are available for at least one plan
- Checking dependency and exclusion constraints
- Detecting duplicate plans or add-ons
- Validating linked features and usage limits
- Identifying unreachable features or usage limits
2. Configuration Space Enumeration
Enumerates all valid subscription configurations (plan + add-on combinations) that satisfy the model’s constraints:- Plan selection constraints
- Add-on availability rules
- Dependency relationships (add-on A requires add-on B)
- Exclusion relationships (add-on A excludes add-on B)
- Cost calculations
3. Constraint Programming
The service models pricing as a CSP with:- Variables: Selected plan, selected add-ons, subscription cost
- Domains: Integer ranges for plans/add-ons, costs in cents
- Constraints: Availability, dependencies, exclusions, feature requirements
Technology Stack
Spring Boot
Java web framework (v3.4.1)
Choco Solver
Constraint solver library (v4.0.9)
Pricing4Java
Pricing model library (v5.5.2)
Maven
Build and dependency management
How It Works
The CSP Service follows a multi-step pipeline when processing a pricing model:Step 1: Parse YAML Input
The service receives a YAML file containing the pricing model in the Pricing2YAML format. It uses theYaml2CSP parser to:
- Load and validate YAML syntax
- Parse into a
PricingManagerobject using Pricing4Java - Handle various error types (file errors, YAML errors, parsing errors)
Step 2: Extract Data Structures
From thePricingManager, the service extracts:
- Lists: Features, usage limits, plans, add-ons, prices
- Binary Matrices: Linked features, plan features, add-on availability
- Numeric Matrices: Usage limits per plan, usage limit extensions
- Dependency Matrices: Add-on dependencies and exclusions
Step 3: Define Choco Variables
The service creates integer variables in the Choco model:Step 4: Post Constraints
The service adds constraints to the model:- Existence constraints: At least one plan or add-on must be selected
- Availability constraints: Selected add-ons must be available for the selected plan
- Dependency constraints: If add-on A is selected and depends on B, then B must be selected
- Exclusion constraints: If add-on A excludes B, they cannot both be selected
- Feature constraints: Plans must have enabled features for positive usage limits
- Duplicate detection: No two plans or add-ons should be identical
Step 5: Solve and Return Results
Choco’s solver:- Propagates constraints to reduce variable domains
- Searches for all solutions using backtracking
- Returns the configuration space with all valid subscriptions
Constraint Types
The CSP Service implements several types of constraints:Structural Constraints
Structural Constraints
- Each plan must have at least one feature
- Each add-on must provide at least one feature, usage limit, or extension
- Each add-on must be available for at least one plan
- Features and usage limits must be reachable from at least one plan or add-on
Relational Constraints
Relational Constraints
- Add-ons must be available for the selected plan
- Add-on dependencies: if A depends on B, selecting A forces B to be selected
- Add-on exclusions: if A excludes B, they cannot both be selected
- No circular dependencies between add-ons
Semantic Constraints
Semantic Constraints
- If a feature is linked to usage limits, at least one linked limit must be positive
- If a usage limit is positive and linked to features, at least one linked feature must be enabled
- Usage limits must be non-negative
- No duplicate plans (same features and usage limits)
- No duplicate add-ons (same features, limits, dependencies, exclusions)
Cost Constraints
Cost Constraints
- Plan cost is determined by the selected plan’s price
- Add-on costs are calculated only for selected add-ons
- Total subscription cost = plan cost + sum of selected add-on costs
- All costs are represented in cents (scaled by 100)
Configuration
The CSP Service is configured via Docker Compose:docker-compose.yml
Environment Variables
The port on which the service listens for HTTP requests.
Logging level. Options:
DEBUG, INFO, WARN, ERROR.Service Endpoints
The CSP Service exposes a single REST endpoint:- POST /validate - Validates a pricing model and returns the configuration space
Dependencies
The service relies on two key Java libraries:Choco Solver 4.0.9
Choco is an open-source Java library for constraint programming. It provides:- Integer, Boolean, and Set variables
- Propagation-based constraint solving
- Explanation engine for unsatisfiable problems
- Search strategies and heuristics
- GitHub Repository
Pricing4Java 5.5.2
Pricing4Java is a library developed by the ISA Group for modeling and managing SaaS pricing. It provides:- The
PricingManagerdomain model - YAML parsing and serialization
- Feature and usage limit types
- Version management
- GitHub Repository
Error Handling
The CSP Service returns structured error messages with different error types:The type of error encountered:
SUCCESS- Model is validVALIDATION_ERROR- Constraint violation detectedFILE_ERROR- File path invalid or file not foundYAML_ERROR- YAML syntax errorPARSER_ERROR- Error parsing pricing model
List of error messages explaining what went wrong. Each constraint that fails includes a descriptive name explaining the issue.
Performance Considerations
The solving time depends on:- Number of plans and add-ons
- Number of features and usage limits
- Complexity of dependency/exclusion relationships
- Presence of linked features
- Simple models (2-4 plans, 0-2 add-ons): < 1 second
- Medium models (5-10 plans, 3-10 add-ons): 1-5 seconds
- Complex models (10+ plans, 10+ add-ons): 5-30 seconds
Next Steps
Solver Endpoint
Detailed API documentation for the /validate endpoint
Analysis API
Learn how the Analysis API uses the CSP Service