Skip to main content

Configuration

This document explains how to configure the ad server, including environment variables, placements, creatives and campaigns. All entities are stored in PostgreSQL. The server creates the tables on startup and the fake_data tool loads demo data when run. When the database is empty it first adds a demo publisher (ID 1, API key demo123).

Environment Variables

VariableDefaultDescription
Core Settings
PORT8787HTTP server port
READ_TIMEOUT5sHTTP read timeout
WRITE_TIMEOUT10sHTTP write timeout
REDIS_ADDRlocalhost:6379Redis connection string for operational counters
CLICKHOUSE_DSNclickhouse://default:@localhost:9000/default?async_insert=1&wait_for_async_insert=1ClickHouse connection string with async inserts
POSTGRES_DSNpostgres://postgres@127.0.0.1:5432/postgres?sslmode=disablePostgreSQL connection string
Database Connection Pooling
DB_MAX_OPEN_CONNS25Maximum PostgreSQL connections
DB_MAX_IDLE_CONNS5Maximum idle PostgreSQL connections
DB_CONN_MAX_LIFETIME5mPostgreSQL connection max lifetime
DB_CONN_MAX_IDLE_TIME1mPostgreSQL connection max idle time
CH_MAX_OPEN_CONNS100Maximum ClickHouse connections
CH_MAX_IDLE_CONNS25Maximum idle ClickHouse connections
CH_CONN_MAX_LIFETIME5mClickHouse connection max lifetime
CH_CONN_MAX_IDLE_TIME1mClickHouse connection max idle time
Other Settings
GEOIP_DBdata/GeoLite2-Country.mmdbGeoIP database path
DIMENSIONS_CONFIG_PATHconfig/dimensions.yamlPath to dimension registration configuration file
DEBUG_TRACEfalseEnable debug tracing for ad selection
ENVproductionEnvironment type (development, staging, production)
LOG_LEVELvariesOverride log level (DEBUG, INFO, WARN, ERROR)
RELOAD_INTERVAL30sAutomatic reload interval for campaign data
Distributed Tracing
TRACING_ENABLEDfalseEnable OpenTelemetry distributed tracing
TEMPO_ENDPOINTlocalhost:4317Tempo OTLP gRPC endpoint for trace export
TRACING_SAMPLE_RATE1.0Trace sampling rate (0.0 to 1.0)
Authentication & Security
TOKEN_SECRETrequiredRandom string for token signing
TOKEN_TTL30mToken expiration time
CTR Estimation
DEFAULT_CTR0.5Baseline CTR for new CPC line items
CTR_WEIGHT2.0Smoothing weight for CTR calculations
Rate Limiting
RATE_LIMIT_ENABLEDtrueEnable/disable rate limiting
RATE_LIMIT_CAPACITY100Token bucket capacity (burst size)
RATE_LIMIT_REFILL_RATE10Tokens added per second
CTR Optimization
CTR_OPTIMIZATION_ENABLEDfalseEnable ML CTR optimization for CPC line items
CTR_PREDICTOR_URLhttp://localhost:8000URL of the CTR prediction service
CTR_PREDICTOR_TIMEOUT100msTimeout for CTR prediction requests
CTR_PREDICTOR_CACHE_TTL5mCache TTL for CTR predictions
PROGRAMMATIC_BID_TIMEOUT800msTimeout for external programmatic bid requests

Placements

Placements describe the ad slots available on your site.

FieldTypeDescription
idstringUnique identifier referenced by SDK and API
publisher_idintPublisher ID this placement belongs to
widthintDefault width in pixels (can be overridden)
heightintDefault height in pixels (can be overridden)
formatsarrayAllowed creative formats: html, native

Example:

{"id": "header", "publisher_id": 1, "width": 320, "height": 50, "formats": ["html"]}

Creatives

Creatives are the actual ads that can serve in a placement.

FieldTypeDescription
idintCreative identifier
placement_idstringPlacement this creative belongs to
line_item_idintLine item controlling delivery rules
campaign_idintCampaign for reporting
publisher_idintPublisher ID
htmlstringMarkup for HTML creatives
nativeobjectAsset object for native creatives
widthintCreative width (must match placement)
heightintCreative height (must match placement)
formatstringCreative format: html or native

Example:

{"id": 1, "placement_id": "header", "line_item_id": 101, "campaign_id": 101, "html": "<div>Ad</div>", "width": 320, "height": 50, "format": "html"}

Campaigns and Line Items

Campaigns serve as lightweight containers for reporting purposes. The core of delivery control, targeting, and budgeting lies within line items.

Line Item Fields

FieldTypeDescription
IDint64Unique identifier for the line item
CampaignIDint64Identifier of the parent campaign
PublisherIDint64Identifier of the publisher
NamestringHuman-readable name for identification
StartDate / EndDatetime.TimeFlight period for line item activity
DailyImpressionCapintMax impressions per day (0 = no cap)
DailyClickCapintMax clicks per day (0 = no cap)
CPMfloat64Bid price per thousand impressions
CPCfloat64Bid price per click
eCPMfloat64Effective CPM for auction ranking
BudgetTypeenumSpending model: cpm, cpc, or flat
BudgetAmountfloat64Total monetary budget for line item
Spendfloat64Currently accumulated spend
PaceTypeenumDelivery pacing: asap, even, or pid
PriorityenumPublisher-defined priority level
FrequencyCapintMax impressions per user in window
FrequencyWindowdurationTime window for frequency capping
CountrystringISO 3166-1 alpha-2 country code
RegionstringState/province code for targeting
DeviceTypestringDevice targeting: mobile, desktop, tablet
OSstringOperating system targeting
BrowserstringBrowser targeting
KeyValuesmapCustom key-value pairs for targeting
TypeenumLine item type: direct or programmatic
EndpointstringURL for programmatic bid requests
ActiveboolWhether line item is enabled

Budget Types

  • cpm: Cost Per Mille (thousand impressions). Spend accrued per impression.
  • cpc: Cost Per Click. eCPM calculated from CPC bid and estimated CTR. Spend accrued per click.
  • flat: Fixed budget for sponsorships or fixed-price deals.

Pacing Types

  • asap: Deliver impressions as quickly as possible with hard cap enforcement.
  • even: Spread impressions evenly throughout the day.
  • pid: Use PID controller for dynamic pacing with safety checks.

CTR Calculation

For CPC line items, CTR is estimated using smoothed values to prevent zero eCPM:

CTR = (clicks + DEFAULT_CTR x CTR_WEIGHT) / (impressions + CTR_WEIGHT)
eCPM = CPC x CTR x 1000

See CTR Estimation environment variables above.

Additional Configuration

Token Security

Set TOKEN_SECRET to enable token signing for impression and click tracking. Tokens expire after TOKEN_TTL (default 30m).

Programmatic Line Items

Programmatic line items call their Endpoint to retrieve OpenRTB bids. See Programmatic Demand. Use /test/bid for development testing.

Rate Limiting

Built-in rate limiting protects against request floods. See Rate Limiting Documentation for details.

Dimension Registration

Configure registered dimensions with type validation and indexing via YAML configuration. See Dimension Registration for complete configuration options and examples.

Key benefits:

  • Type validation (enum, string, number, boolean)
  • ClickHouse indexing for improved analytics performance
  • Structured configuration with backward compatibility

Set DIMENSIONS_CONFIG_PATH to your configuration file path.