Brewing Coffee : Setting Up Temporal for Best-Coffee-Shop

AniruddhaAniruddha
2 min read

Welcome to the "Best Coffee Shop" series — where we build a real-world distributed application using Temporal.io and Python!

Imagine you're at your favorite coffee place. You place an order. That simple action sets off a whole chain of tasks: someone needs to collect your payment, grab ingredients, brew the coffee, and finally serve it to you. Now imagine scaling that to hundreds of customers, handling retries, failures, cancellations, and observability — that’s where Temporal shines.

What You'll Learn

  • What Temporal is and how it works

  • Key concepts: Workflows, Activities, Signals, Queries, Task Queues

  • How to use Temporal's Python SDK

Use Case: The Best Coffee Shop

  1. Customer places an order: This triggers a Temporal workflow.

  2. Workflow Step 1 – Ask for Payment: An activity asks the customer to pay. The workflow waits for a signal indicating payment is complete.

  3. Workflow Step 2 – Collect Ingredients: Once paid, we collect necessary ingredients.

  4. Workflow Step 3 – Brew Coffee: The actual coffee gets brewed.

  5. Workflow Step 4 – Serve Coffee: The customer gets their coffee, and the workflow is marked as complete.

Tools & Tech Stack

  • Temporal Python SDK for workflow and activity logic

  • FastAPI to simulate a customer-facing API

  • Docker Compose to run Temporal and services together

  • SvelteJS for allowing customer to place order & receive coffee (everything gonna be virtual)

By the end of this tutorial, you'll have a clear understanding of how Temporal helps orchestrate complex, reliable, stateful workflows using simple Python code.

Setup

Let's start with setting-up temporal.

Create directory best-coffee-shop & add docker-compose.yml

mkdir best-coffee-shop
touch best-coffee-shop/docker-compose.yml

file : best-coffee-shop/docker-compose.yml

services:
  postgresql:
    container_name: temporal-postgresql
    environment:
      POSTGRES_PASSWORD: temporal
      POSTGRES_USER: temporal
    image: postgres
    networks:
      - best-coffee-network
    ports:
      - 5432:5432
    volumes:
      - /var/lib/postgresql/data
  temporal:
    container_name: temporal
    depends_on:
      - postgresql
    environment:
      - DB=postgres12
      - DB_PORT=5432
      - POSTGRES_USER=temporal
      - POSTGRES_PWD=temporal
      - POSTGRES_SEEDS=postgresql
    image: temporalio/auto-setup
    networks:
      - best-coffee-network
    ports:
      - 7233:7233
  temporal-ui:
    container_name: temporal-ui
    depends_on:
      - temporal
    environment:
      - TEMPORAL_ADDRESS=temporal:7233
      - TEMPORAL_CORS_ORIGINS=http://localhost:3000
      - TEMPORAL_CSRF_COOKIE_INSECURE=true
    image: temporalio/ui
    networks:
      - best-coffee-network
    ports:
      - 8080:8080

networks:
  best-coffee-network:
    driver: bridge
    name: best-coffee-network

Try It Out

We are setting-up DB, temporal & temporal UI.

Run

best-coffee-shop> docker-compose up

Visit http://localhost:8080 in browser. It will show temporal UI. Next we will create workflow.

Code for this post

You can find the code up to this 👉: Code repo

0
Subscribe to my newsletter

Read articles from Aniruddha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aniruddha
Aniruddha