Configuration Methods

Flexprice can be configured using:

  1. Environment variables (recommended)
  2. Configuration files
  3. Command-line arguments (for specific overrides)

Environment Variables

Environment variables are the recommended way to configure Flexprice. All environment variables are prefixed with FLEXPRICE_. Here’s a comprehensive list of available variables:

Deployment Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_DEPLOYMENT_MODEDeployment mode (local, api, consumer, temporal_worker, aws_lambda_api, aws_lambda_consumer)localNo
FLEXPRICE_SERVER_ADDRESSServer address and port:8080No

Authentication Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_AUTH_PROVIDERAuthentication provider (flexprice, supabase)flexpriceNo
FLEXPRICE_AUTH_SECRETSecret key for authentication-Yes
FLEXPRICE_AUTH_SUPABASE_BASE_URLSupabase base URL (if using Supabase auth)-Only if using Supabase
FLEXPRICE_AUTH_SUPABASE_SERVICE_KEYSupabase service key-Only if using Supabase
FLEXPRICE_AUTH_API_KEY_HEADERHeader name for API key authenticationx-api-keyNo
FLEXPRICE_AUTH_API_KEY_KEYSJSON string of API keys configuration-No

Database Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_POSTGRES_HOSTPostgreSQL hostlocalhostNo
FLEXPRICE_POSTGRES_PORTPostgreSQL port5432No
FLEXPRICE_POSTGRES_USERPostgreSQL usernameflexpriceNo
FLEXPRICE_POSTGRES_PASSWORDPostgreSQL passwordflexprice123Yes
FLEXPRICE_POSTGRES_DBNAMEPostgreSQL database nameflexpriceNo
FLEXPRICE_POSTGRES_SSLMODEPostgreSQL SSL mode (disable, require)disableNo
FLEXPRICE_POSTGRES_AUTO_MIGRATEAutomatically run migrations on startupfalseNo

ClickHouse Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_CLICKHOUSE_ADDRESSClickHouse address (host:port)localhost:9000No
FLEXPRICE_CLICKHOUSE_TLSUse TLS for ClickHouse connectionfalseNo
FLEXPRICE_CLICKHOUSE_USERNAMEClickHouse usernameflexpriceNo
FLEXPRICE_CLICKHOUSE_PASSWORDClickHouse passwordflexprice123Yes
FLEXPRICE_CLICKHOUSE_DATABASEClickHouse database nameflexpriceNo

Kafka Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_KAFKA_BROKERSKafka brokers (comma-separated)localhost:29092No
FLEXPRICE_KAFKA_CONSUMER_GROUPKafka consumer group IDflexprice-consumer-localNo
FLEXPRICE_KAFKA_TOPICKafka topic for eventseventsNo
FLEXPRICE_KAFKA_USE_SASLUse SASL authentication for KafkafalseNo
FLEXPRICE_KAFKA_SASL_MECHANISMSASL mechanism (PLAIN, SCRAM-SHA-256, etc.)-Only if SASL is enabled
FLEXPRICE_KAFKA_SASL_USERSASL username-Only if SASL is enabled
FLEXPRICE_KAFKA_SASL_PASSWORDSASL password-Only if SASL is enabled
FLEXPRICE_KAFKA_CLIENT_IDKafka client IDflexprice-client-localNo

Temporal Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_TEMPORAL_ADDRESSTemporal service addresslocalhost:7233No
FLEXPRICE_TEMPORAL_TLSUse TLS for Temporal connectionfalseNo
FLEXPRICE_TEMPORAL_NAMESPACETemporal namespacedefaultNo
FLEXPRICE_TEMPORAL_TASK_QUEUETemporal task queuebilling-task-queueNo
FLEXPRICE_TEMPORAL_API_KEYTemporal API key-Only if using Temporal Cloud
FLEXPRICE_TEMPORAL_API_KEY_NAMETemporal API key name-Only if using Temporal Cloud

Logging and Monitoring

VariableDescriptionDefaultRequired
FLEXPRICE_LOGGING_LEVELLogging level (debug, info, warn, error)infoNo
FLEXPRICE_SENTRY_ENABLEDEnable Sentry error reportingfalseNo
FLEXPRICE_SENTRY_DSNSentry DSN-Only if Sentry is enabled
FLEXPRICE_SENTRY_ENVIRONMENTSentry environmentdevelopmentNo
FLEXPRICE_SENTRY_SAMPLE_RATESentry sampling rate (0.0-1.0)1.0No

DynamoDB Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_DYNAMODB_IN_USEUse DynamoDB for event storagefalseNo
FLEXPRICE_DYNAMODB_REGIONAWS region for DynamoDBus-east-1Only if DynamoDB is enabled
FLEXPRICE_DYNAMODB_EVENT_TABLE_NAMEDynamoDB table name for eventseventsOnly if DynamoDB is enabled

Webhook Configuration

VariableDescriptionDefaultRequired
FLEXPRICE_WEBHOOK_MAX_RETRIESMaximum number of webhook retry attempts3No
FLEXPRICE_WEBHOOK_INITIAL_INTERVALInitial retry interval (e.g., 1s)1sNo
FLEXPRICE_WEBHOOK_MAX_INTERVALMaximum retry interval (e.g., 10s)10sNo
FLEXPRICE_WEBHOOK_MULTIPLIERBackoff multiplier for retries2.0No
FLEXPRICE_WEBHOOK_MAX_ELAPSED_TIMEMaximum total retry time (e.g., 2m)2mNo

Event Publishing

VariableDescriptionDefaultRequired
FLEXPRICE_EVENT_PUBLISH_DESTINATIONEvent publishing destination (kafka, dynamodb, all)kafkaNo

Using a .env File

For local development, you can use a .env file to set environment variables. Create a file named .env in the root directory of your project:

# Deployment Configuration
FLEXPRICE_DEPLOYMENT_MODE=local
FLEXPRICE_SERVER_ADDRESS=":8080"

# Authentication Configuration
FLEXPRICE_AUTH_PROVIDER="flexprice"
FLEXPRICE_AUTH_SECRET="your_secure_secret_key"
FLEXPRICE_AUTH_API_KEY_HEADER="x-api-key"

# Database Configuration
FLEXPRICE_POSTGRES_HOST=localhost
FLEXPRICE_POSTGRES_PORT=5432
FLEXPRICE_POSTGRES_USER=flexprice
FLEXPRICE_POSTGRES_PASSWORD=flexprice123
FLEXPRICE_POSTGRES_DBNAME=flexprice
FLEXPRICE_POSTGRES_SSLMODE=disable
FLEXPRICE_POSTGRES_AUTO_MIGRATE=true

# ClickHouse Configuration
FLEXPRICE_CLICKHOUSE_ADDRESS=localhost:9000
FLEXPRICE_CLICKHOUSE_TLS=false
FLEXPRICE_CLICKHOUSE_USERNAME=flexprice
FLEXPRICE_CLICKHOUSE_PASSWORD=flexprice123
FLEXPRICE_CLICKHOUSE_DATABASE=flexprice

# Kafka Configuration
FLEXPRICE_KAFKA_BROKERS=localhost:29092
FLEXPRICE_KAFKA_CONSUMER_GROUP=flexprice-consumer-local
FLEXPRICE_KAFKA_TOPIC=events

# Logging Configuration
FLEXPRICE_LOGGING_LEVEL=debug

When using Docker Compose, you can specify environment variables in your docker-compose.yml file or use the .env file directly.

Configuration File

For more complex configurations, you can use a YAML configuration file. By default, Flexprice looks for a file named config.yaml in the internal/config directory:

deployment:
  mode: "local" # "local", "docker", "production"

server:
  address: ":8080"

auth:
  provider: "flexprice" # "flexprice" or "supabase"
  secret: "your_secure_secret_key"
  supabase:
    base_url: "http://localhost:54321"
    service_key: "<supabase service key>"
  api_key:
    header: "x-api-key"
    keys:
      "your_api_key_hash":
        tenant_id: "00000000-0000-0000-0000-000000000000"
        user_id: "00000000-0000-0000-0000-000000000000"
        name: "Dev API Keys"
        is_active: true

kafka:
  brokers: "localhost:29092"
  consumer_group: "flexprice-consumer-local"
  topic: "events"
  use_sasl: false
  sasl_mechanism: ""
  sasl_user: ""
  sasl_password: ""
  client_id: "flexprice-client-local"

clickhouse:
  address: "localhost:9000"
  tls: false
  username: "flexprice"
  password: "flexprice123"
  database: "flexprice"

postgres:
  host: "localhost"
  port: 5432
  user: "flexprice"
  password: "flexprice123"
  dbname: "flexprice"
  sslmode: "disable"
  auto_migrate: false

temporal:
  address: "localhost:7233"
  tls: false
  namespace: "default"
  task_queue: "billing-task-queue"

Environment variables take precedence over configuration file settings. If an environment variable is set, it will override the corresponding value in the configuration file.

Production Best Practices

When configuring Flexprice for production, follow these best practices:

Security

  1. Use strong, unique passwords for all database users
  2. Enable SSL/TLS for all external connections
  3. Set up a firewall to restrict access to your servers
  4. Use a secure API key for authentication
  5. Rotate secrets regularly to maintain security

Performance

  1. Allocate sufficient resources to each component based on your expected load
  2. Monitor resource usage and scale as needed
  3. Configure appropriate Kafka settings for your message volume
  4. Adjust database connection pools based on your workload

High Availability

  1. Set up database replication for PostgreSQL and ClickHouse
  2. Deploy multiple API server instances behind a load balancer
  3. Configure Kafka with multiple brokers in a cluster
  4. Implement automated backups for all data stores

Next Steps

After configuring your Flexprice instance, you should:

  1. Set up monitoring and alerting for your instance
  2. Implement a backup strategy for your data
  3. Plan for regular updates to keep your instance secure and up-to-date