Devizur
All insightsEngineering

PostgreSQL for Business Platforms: More Than CRUD

How relational modelling, transactions, indexing, JSONB and database-level constraints support commerce, POS and operational systems.

Soud Al Raihan26 March 20263 min read
OrdersRelational ModelTransactionsIndexesJSONB

History and context

1970s
Relational database theory established a durable model for structured business data.
1980s–1990s
SQL databases became the backbone of commercial transaction systems.
PostgreSQL lineage
PostgreSQL evolved from the POSTGRES research lineage into a mature open-source relational database.
Current PostgreSQL
Current PostgreSQL documentation lists B-tree, Hash, GiST, SP-GiST, GIN and BRIN index types, plus extensive JSON and SQL/JSON capabilities.

Why business data is relational

Orders have lines. Lines refer to products. Products belong to categories. Payments refer to orders. Inventory belongs to products and locations. These relationships are not incidental; they are the business model.

Constraints make invalid states harder

PostgreSQL
CREATE TABLE sales_order_line (
    order_line_id BIGSERIAL PRIMARY KEY,
    order_id BIGINT NOT NULL
        REFERENCES sales_order(order_id),
    product_id BIGINT NOT NULL,
    quantity NUMERIC(18,3) NOT NULL
        CHECK (quantity > 0)
);

Transactions protect multi-step state changes

Financial and inventory workflows frequently require atomicity. Either all required changes commit or none should.

SQL
BEGIN;

UPDATE inventory_balance
SET reserved_quantity = reserved_quantity + 2
WHERE product_id = 148
  AND location_id = 3;

INSERT INTO sales_order (...);

COMMIT;

Index types follow access patterns

B-tree remains the normal default for many equality and ordering queries. PostgreSQL also provides specialised types such as GIN, which is useful for composite values and is commonly used for JSONB and full-text style access patterns.

SQL
CREATE INDEX ix_product_attributes_gin
ON product
USING GIN (attributes jsonb_path_ops);

JSONB: flexible, but not an excuse to abandon modelling

JSONB works well for controlled flexible structures such as configuration snapshots or attributes whose shape varies. Core relational ownership should still be modelled relationally when constraints and joins matter.

SQL
SELECT product_id
FROM product
WHERE attributes @> '{"waterproof": true}'::jsonb;

Concurrency belongs in the design

Booking and inventory systems may need row locks, transaction isolation or advisory locks to coordinate competing operations. The exact mechanism should match the resource being protected and the transaction boundary.

Business value and practical considerations

Pros

  • Strong transactions
  • Rich SQL
  • Multiple index strategies
  • JSONB flexibility
  • Open-source ecosystem

Considerations / responsibilities

  • Schema design still matters
  • Indexes can hurt writes
  • Long transactions create contention
  • JSONB can be overused
SA
Soud Al RaihanData and backend engineering · Devizur

References

Primary documentation used for terminology and current platform guidance: