Architectural Brief: Solar Pricing Engine
The operations team was updating product prices by hand every morning. Several suppliers, about 2,100 variants, one person with a spreadsheet. This is the system that replaced that process and made the store react to competitor pricing on Idealo during the day instead of once each morning.
System Topology
Infrastructure Decisions
- Compute: Docker container on a Linux VPS, started by a systemd timer every 15 minutes during the day and hourly overnight. Chose a long-running container over Lambda because full runs averaged 8 to 11 minutes in autumn 2026, and Lambda's 15-minute timeout leaves no margin for retries. The service is a oneshot unit, so systemd skips a trigger while a run is still going instead of starting a second copy. Each release is a thin image layer, and the previous image stays on the host for rollback.
- Data Layer: Pandas DataFrames in-memory. Chose over PostgreSQL or SQLite because this is a batch script, not an API. No concurrent reads. Everything loads, processes, and exports in a single execution. The only state kept between runs is a small file on the VPS volume that records what Shopify last confirmed, so unchanged variants aren't resent.
- Core Language: Python with no web framework. Chose Python for pandas ecosystem and the team's familiarity. No FastAPI or Flask: there's no API to serve. The entry point is
run.pycallingrun_pricing_bot()with a 2-hour timeout watchdog. - Shopify Integration: GraphQL Admin API with Bulk Operations (JSONL staged upload, mutation, polling, result download). Chose over REST Admin API loops because one call per variant runs into rate limits at this catalog size. Since November 2026 the sync sends only variants whose confirmed values changed. Sets of up to 50 products go out as direct
productVariantsBulkUpdatecalls, because a small bulk operation can sit in Shopify's queue far longer than the update takes. The daily full sync still uses bulk. - Data Bus: Google Drive API (service account). Chose over S3 because the operations team manages pricing rules, supplier feeds, and competition monitoring in Google Sheets. Google Drive is both data source and data sink. Replacing it with S3 would have required rebuilding their entire workflow.
- Idealo Integration: Custom scraping API, offer aggregation, and CSV export pipeline. No official Idealo API for real-time pricing data. Competition data flows through a separate module (
idealo_operations/) with its own retry logic.
Constraints That Shaped the Design
- Input: One price feed per supplier (CSV, XLSX, varying column names, mixed decimal formats) downloaded from Google Drive subfolders. Base product catalog pulled from Matrixify CSV export URL. Pricing rules from a Google Sheet with
price-logicandprice-logic-exclusionstabs. - Output: Updated prices and metafields synced to Shopify (GraphQL). A CSV price feed for Idealo. Backup snapshots of each run's supplier files to Google Drive.
- Scale Handled: About 2,100 Shopify variants per run. At ten times that, the in-memory DataFrame approach would need chunked processing and partitioned bulk operations. The pricing logic itself is stateless per-product and would scale linearly.
- Hard Constraints: Shopify API rate limit at 80% buffer (
SHOPIFY_RATE_LIMIT_BUFFER=0.8). Bulk operation timeout at 3,600 seconds.retry_with_backoffdecorator on all Google Drive and API calls (5 retries, exponential backoff, 60s max wait). A 2-hour global timeout inrun.pykills the process if anything hangs.
Decision Log
| Decision | Alternative Rejected | Why |
|---|---|---|
| Two-pass SKU matching (product SKU then supplier part number) | Fuzzy string matching | Solar part numbers are dense alphanumerics. STP8.0-3AV-40 and STP10.0-3AV-40 are different products at different prices, one an 8kW inverter and one a 10kW. Fuzzy matching produced dangerous false positives. An exact match is either right or missing. A fuzzy match can be confidently wrong. |
| Per-supplier cleaner functions (one per supplier format) | Generic data normalizer with rules dictionary | Three suppliers in, the generic approach was already unreadable. Each supplier has unique format quirks: German decimals, text stock values, inconsistent column names. Isolated cleaners are ugly but safe to modify independently. |
| Category surcharge before pricing rules | Surcharge after pricing rules | The category-specific surcharge must be part of the base cost before margin brackets apply. Applying it after creates compound markup drift that looks plausible but is consistently a few percent too high. Caught this only after manual spot-checking specific products. |
| JSONL staged bulk mutations for full syncs | Individual GraphQL mutations | Sending every variant one call at a time means waiting on rate-limit pauses. A JSONL upload sends the whole catalog as one bulk mutation. The complexity cost is a state machine for upload-mutate-poll-download. Small change sets skip it and go out as direct calls. |
| Google Drive as primary I/O | AWS S3 or managed file store | The client's operations team manages pricing rules, competitor monitoring, and supplier feeds in Google Sheets. Forcing a workflow change would have delayed delivery by months. Google Drive API with service account auth handles both read and write. |
| Supplier selection with exclusion priority | Simple lowest-price deduplication | The operations team sets fixed prices on specific SKUs via a Google Sheet. Automation must not override these manual decisions. Additionally, the cheapest supplier row might have zero inventory. The selection logic checks exclusions first, then inventory, then price. |