Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 40 ยท Getting Started

How Online Shops Work

See how an online shop fits together: storefront, backend, admin, payments, shipping, tax and search, plus business models and the build-vs-buy choice.

An online shop looks simple from the outside: you browse products, click "Buy" and a parcel arrives. Behind that click sits a surprising amount of software. Prices must be right, stock must be real, money must move safely, taxes must be calculated, and a human must be able to ship the box. If any one of those parts fails, the customer notices.

This tutorial teaches the ideas that every shop shares, whatever platform or language it uses. In this first lesson you get the big picture: the parts of a shop, the outside services it relies on, the common business models, and how to decide between building and buying. Later lessons zoom into each part and give you small runnable programs that model it.

The three faces of a shop

Almost every shop has three layers that talk to each other.

  • Storefront. The pages customers see: home, category listings, product pages, cart, checkout and account area. It can be rendered on the server, built as a single-page app, or be a mix. Its job is to be fast, clear and trustworthy.
  • Backend. The rules and the data. It stores products, prices, stock, customers and orders, and it enforces the rules ("you can't buy more than we have", "this coupon expired"). The storefront should never be the place where a rule lives, because anything running in a browser can be tampered with.
  • Admin. The tools for the shop's staff: add products, change prices, see orders, print labels, issue refunds, run reports. It is often the largest part of a platform and the part developers underestimate most.
flowchart LR
    C(["Customer"]) --> S["Storefront"]
    S --> B["Backend<br/>(catalog, cart, orders)"]
    A(["Staff"]) --> M["Admin"]
    M --> B
    B --> D[("Database")]
    B --> P["Payments"]
    B --> H["Shipping"]
    B --> T["Tax"]
    B --> Q["Search"]
    B --> E["Email"]

Customers and staff use different front doors, but both reach the same backend and data.

What happens when someone buys

Follow one purchase through the system. The steps below are the skeleton of almost every shop.

  1. The customer finds a product (browse or search) and opens its page.
  2. They add it to a cart. The backend checks that the item exists and is for sale.
  3. At checkout they enter an address and choose a shipping method. The backend calculates shipping, discounts and tax and produces a total.
  4. They pay. The payment provider checks the card and confirms or declines.
  5. The backend creates an order, reduces available stock and sends a confirmation email.
  6. Staff (or a warehouse partner) pick, pack and ship the goods. The customer gets tracking information.
  7. Later, the customer may return something and receive a refund.

Each of those steps becomes its own lesson in this tutorial. The run below is a tiny stand-in that only prints the sequence, but it shows an important idea: the order is a series of states, and each step can only happen after the one before it.

JS A purchase as a sequence of steps

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice how many steps involve someone else's system. That is normal.

The services around your code

A shop rarely does everything itself. It plugs into specialised services, usually over HTTP APIs:

Concern What it does Why you rarely build it
Payments Charges cards and wallets, handles bank transfers Strict security rules and bank relationships
Shipping Quotes rates, buys labels, tracks parcels Carriers each have different APIs
Tax Works out sales tax, VAT or GST for an address Rules change often and vary by place
Search Fast, typo-tolerant product search and filters A database LIKE query does not scale to good relevance
Email Sends receipts and shipping updates Deliverability is a specialty
Analytics Measures traffic and conversion Needs events from many pages

Each integration adds a failure mode. A payment provider can time out, a carrier API can be down, a tax service can return an error. A well-built shop keeps working, or fails clearly, when a partner misbehaves. You will see patterns for this in the payments, integrations and architecture lessons.

Note: Keep a clear line between what you own and what you rent. You own your catalog, orders and customer data. You rent the capability to charge cards or print labels. Design your code so a partner can be swapped without rewriting your orders.

Business models

"E-commerce" covers several different businesses. The model changes what you must build.

  • B2C (business to consumer). A shop sells to individuals. Prices are public, checkout is quick and payment is usually by card or wallet.
  • B2B (business to business). The buyer is a company. Expect customer-specific prices, approval flows, purchase orders, invoices with payment terms and tax-exempt buyers.
  • Marketplace. Many sellers share one storefront. The operator handles payments and splits money between sellers, takes a commission and deals with disputes between buyers and sellers.
  • Subscriptions. Customers pay on a schedule for a product or service. You need recurring billing, failed-payment recovery and a way to pause or cancel.
  • DTC (direct to consumer). A brand sells its own products directly rather than through retailers. It owns the customer relationship, brand experience and data, and usually also the logistics.
  • Digital goods. Downloads, licenses and courses. There is nothing to ship, but you must deliver access reliably and handle licensing and tax rules for digital products.

Real businesses often mix several of these. A DTC brand may add a B2B wholesale portal and a subscription for refills. A good domain model (next lesson) leaves room for that growth.

JS How the model changes the requirements

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Platform or custom build?

Early on, the biggest decision is whether to use an existing platform (Shopify, WooCommerce, Magento and similar) or to write a shop yourself. There is no universal answer, but the trade-offs are predictable.

A platform gives you a working catalog, cart, checkout, admin, payment integrations and a theme system on day one. Security patches and many compliance details are handled for you. You pay with money (fees or hosting), with less freedom over behavior, and sometimes with lock-in to the vendor's data shapes.

A custom build gives you exact control over the experience and the rules, which matters when your pricing, inventory or checkout is unusual. You pay with time: you must build and maintain everything in this tutorial, including the unglamorous parts like refunds, tax and admin screens.

A middle road is common: use a platform for the commodity parts and extend it with your own code for what makes the business different. Even if you only ever use platforms, knowing the fundamentals tells you what a platform is doing for you, how to extend it safely and where it will hurt. The lesson Choosing a Platform: Build vs Buy returns to this decision with more detail.

flowchart TB
    Q{"Is your shop<br/>unusual?"}
    Q -- "No, standard catalog and checkout" --> P["Use a hosted platform"]
    Q -- "Somewhat, special rules or UX" --> X["Platform plus custom extensions"]
    Q -- "Yes, core of the business" --> C["Custom or composable build"]

A rough starting point for the build-or-buy decision, not a rule.

What this tutorial covers

The chapters follow the life of an order: the domain model and money, the catalog, inventory, pricing and tax, cart and checkout, payments, shipping and returns, search, growth, security and compliance, and finally architecture. Throughout, you will use small programs in JavaScript, Node.js and Python as live stand-ins for each idea. They are not production code for any specific platform; they teach the logic you will meet on all of them.

Tip: When you read about a feature in a platform's documentation, ask which of the shop's parts it belongs to: storefront, backend, admin or an outside service. That habit makes unfamiliar systems easier to understand.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should business rules such as stock limits live in the backend rather than the storefront?

    The visitor controls their own browser. The storefront can show friendly messages, but the backend must enforce the rules.
  2. 2. Which business model needs customer-specific prices, invoices with payment terms and tax-exempt buyers?

    Companies buying from companies usually negotiate prices, pay on terms and may be exempt from some taxes. These are typical B2B requirements.
  3. 3. Which of these is usually a good reason to rent a service instead of building it yourself?

    Payments involve banks and strict security requirements, so most shops use a payment provider. Catalog and orders are data you should own.
  4. 4. What is a fair summary of the platform versus custom build trade-off?

    A platform gives you a working shop quickly with less freedom. A custom build gives freedom and costs time and maintenance.

Summary

  • A shop has a storefront for customers, a backend that owns data and rules, and an admin for staff.
  • Payments, shipping, tax, search and email are usually outside services, each a possible point of failure.
  • A purchase moves through ordered steps: cart, totals, payment, order, stock, email, shipment.
  • B2C, B2B, marketplace, subscription, DTC and digital models need different features on top of a shared core.
  • Choosing a platform or a custom build is a trade between speed and control, and a mix is common.

Next: The Core Domain Model, where you name the entities every shop is built from.