Variant Systems

PostgreSQL for E-commerce

The database that never sells an item you don't have in stock.

Variant Systems builds industry-specific software with the tools that fit the problem.

Why this combination

  • ACID transactions guarantee that inventory decrements and order creation happen atomically. No overselling, no phantom stock.
  • Full-text search with tsvector handles product search without bolting on a separate search engine for most catalog sizes.
  • JSONB columns store flexible product attributes without schema migrations for every new product category.
  • Proven performance at scale. PostgreSQL handles millions of products and thousands of concurrent orders reliably.

Transactional Integrity for Orders

E-commerce databases have one job they absolutely cannot get wrong: don’t sell what you don’t have. When two customers click “Buy Now” on the last item at the same time, exactly one of them should get it. PostgreSQL’s ACID transactions make this a solved problem. Wrap inventory decrement and order creation in a transaction, and the database guarantees atomicity.

SELECT FOR UPDATE locks the inventory row during checkout. The first transaction decrements stock and commits. The second transaction sees the updated count and handles the out-of-stock case gracefully. No race conditions, no overselling, no angry customers who ordered something you can’t ship. This isn’t theoretical. It’s the foundation that every reliable e-commerce platform is built on.

Flexible Product Catalogs

Products aren’t uniform. A laptop has specs like RAM, storage, and screen size. A shirt has size, color, and material. A book has author, ISBN, and page count. Forcing all of these into rigid relational columns means constant schema migrations or a bloated table with mostly-null columns. PostgreSQL’s JSONB type solves this cleanly.

Store category-specific attributes in a JSONB column. Index the fields you need to filter on with GIN indexes. Query them with PostgreSQL’s JSON operators. Add a new product category with new attributes without touching the schema. The core fields like name, price, SKU, and inventory count stay in proper columns with strong types. The variable attributes live in JSONB with the flexibility to evolve. Best of both worlds.

Search Without Extra Infrastructure

Most e-commerce catalogs don’t need Elasticsearch on day one. PostgreSQL’s full-text search handles product search for catalogs up to hundreds of thousands of items. Create a tsvector column combining product name, description, and tags. Add a GIN index. Your search query runs in milliseconds and supports stemming, ranking, and phrase matching.

For autocomplete, use trigram similarity with the pg_trgm extension. Users type “blck jcket” and get “black jacket” results. Combine full-text search with JSONB attribute filtering and you have faceted search. Filter by category, price range, and attributes all in a single SQL query. When you outgrow PostgreSQL’s search capabilities, migrate to a dedicated search engine. But don’t add that complexity until you actually need it.

Scaling for Traffic Spikes

E-commerce traffic isn’t steady. Black Friday, flash sales, product launches, and viral social media posts create massive spikes. PostgreSQL handles this through read replicas and connection pooling. Route product browsing queries to replicas and reserve the primary for order processing. Your write performance stays consistent even when browsing traffic triples.

Partitioning helps with historical data. Partition orders by month or quarter. Current-month queries run against a small, fast partition. Reporting queries span multiple partitions when needed. Archiving old partitions is as simple as detaching them. Combined with PgBouncer for connection pooling, you can sustain thousands of concurrent checkout sessions without exhausting backend connections — each pooled connection is reused across short-lived transactional queries. Your active tables stay lean, indexes stay small, and performance stays predictable even as your order history grows into the millions.

Compliance considerations

PCI-DSS requires that cardholder data is never stored in plain text. PostgreSQL's encryption functions and column-level access controls enforce this.
Consumer data protection mandates clear retention policies. PostgreSQL's partitioning by date makes it simple to expire and purge old order data.
Fraud prevention queries run against historical order patterns using PostgreSQL's window functions and aggregation capabilities.
Audit trails on order state changes are captured through database triggers that log every update with timestamps and context.

Common patterns we build

  • Inventory management with SELECT FOR UPDATE ensuring concurrent checkouts don't oversell limited stock items.
  • Product catalog with JSONB attributes for flexible specifications that vary across categories like electronics, clothing, and furniture.
  • Full-text search indexes on product names, descriptions, and tags for fast catalog search without external dependencies.
  • Read replicas handling product browsing queries while the primary processes orders, keeping writes fast during traffic spikes.

Other technologies

Services

Building in E-commerce?

We understand the unique challenges. Let's talk about your project.

Get in touch