Please stock the hoodie
You use an online shop. The hoodie is sold out. You type: "Please stock the hoodie."
What happens to your message? The shop saves it. Later the shop counts how many people asked. If many people ask, the shop buys more hoodies. Then you can buy one.
That small story uses seven jobs. Every data system does them.
Key words
| Word | What it means | Example |
|---|---|---|
| Data system | A system that takes in, keeps and gives back data. | An online shop |
| Input | Data going into the system. | You type a request. |
| Search | To find the data you want. | Find every request for a hoodie. |
| Save | To keep data so it is still there later. | The request is stored. |
| Integrate | To join data from different places. | Put a customer name beside a request. |
| Index | A list that points to where data is, for fast finding. | The index at the back of a book |
| Output | Data coming out in a useful form. | A list of the most asked items |
| Feedback loop | What comes out changes what goes in next time. | Stock the hoodie, and fewer people ask. |
| Database | An organised store of data. | The shop database |
The cells students fill in are left blank in this preview.
Quick check: guess the job
Have a go
Quick check: guess the job
3 questionsA data system does seven jobs
A data system does seven jobs.
- Input: data goes in.
- Search: find data.
- Save: keep data.
- Integrate: join data from different places.
- Organise: use an index so finding is fast.
- Output: show or send data.
- Feedback loop: what comes out changes what goes in.
The jobs as a loop
Match the job to what it does
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Try it: the seven jobs in code
requests = [] # Save: a list keeps the data
customers = {1: "Sam", 2: "Aisha"}
requests.append((1, "Hoodie")) # Input: data goes in
requests.append((2, "Hoodie"))
requests.append((1, "Cap"))
for request in requests: # Integrate: a name beside each request
print(customers[request[0]], "asked for", request[1])
hoodie = [] # Search: find the hoodie requests
for request in requests:
if request[1] == "Hoodie":
hoodie.append(request)
print("Hoodie requests:", len(hoodie))
requests.sort() # Organise: put the list in order
print(requests) # Output: show it
# Add one more request and run it again. See the output change.
Make a free account to save your work and track your progress.
The feedback loop
The output shows 2 requests for the hoodie and 1 for the cap. The shop decides to buy 20 hoodies. The decision changes the data: the stock goes up. When customers see it, fewer ask. The output has changed the input.
Watch: what a data system does
Press Play on the short film below. It starts with a request for a hoodie. Then it draws the seven jobs as a loop, shows an index and the small program, and ends with a myth.
Film: what a data system does
What a data system does
Every scene, as text
- Please stock the hoodie. You type: "Please stock the hoodie." (job: input). The shop saves it (job: save). That small story uses seven jobs.
- The jobs as a loop. Input, then Save, then Organise, then Search, then Integrate, then Output; Output leads to the Feedback loop (a decision), which leads back to Input (changes).
- An index makes finding fast. Index: a list that points to where data is, for fast finding. The index at the back of a book (how: look up a word, go to the page). An index on 5 million rows (so: no need to read every row).
- The small program, in run order. Three requests go in (job: input). "Sam asked for Hoodie" (job: integrate; why: the name is joined from customers). "Hoodie requests: 2" (job: search). The list is put in order (job: organise). The sorted list is printed (job: output).
- Myth (false): every step is save. That is not true: each step does its own job. Name the job when you see it. A list keeps the data (job: save). The teapot was asked for 3 times. So the shop buys 20 teapots. The decision changes the data: the stock goes up (job: feedback loop).
Your turn: a request list
A shop keeps a list of the products people ask for. Fill in four functions. The first adds a request. The second counts the requests for one product. The third gives back the product asked for most often. The fourth says if the shop should buy more. Press Run Tests to check your work.
def add_request(requests, product):
# Input and save: put one product name on the end of the list.
# Give back the list.
return None
def count_asks(requests, product):
# Search: how many times is the product in the list?
return -1
def most_asked(requests):
# Output: give back the product that is in the list most often.
# If two have the same count, give back the one that comes first in the list.
# An empty list gives back an empty text "".
return None
def needs_stock(requests, product, limit):
# Feedback loop: the shop buys more when enough people ask.
# Give back True if the product has been asked for limit times or more.
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Extra: Lab: the seven jobs in a real database
Note
Press Start the lab on the bar at the top and wait until it says it is running. The first start takes a little longer. Each Run button types its command into your own terminal. The commands run in order, so do not skip one.
Extra: Set up: trust the server, make sql short
printf '[client]\nssl-verify-server-cert=0\n' > ~/.my.cnf; alias sql='mariadb -h db -u student -pstudent shop -t -e'A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Lab jobs 1 and 3: input and save
The lab has a shop database with real products and customers. You talk to it in SQL (a language for asking a store of tables for data). You add a new table, requests. It records who asked for which product, and when.
Run the first command to make the table. The second command is the input. The third reads the table back. The rows are saved: they are still there.
Extra: Make the requests table
sql "CREATE TABLE requests (id INT AUTO_INCREMENT PRIMARY KEY, customer_id INT NOT NULL, product_id INT NOT NULL, asked_on DATE NOT NULL, FOREIGN KEY (customer_id) REFERENCES customers(id), FOREIGN KEY (product_id) REFERENCES products(id))"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Input: five requests
sql "INSERT INTO requests (customer_id, product_id, asked_on) VALUES (1, 17, '2026-10-01'), (2, 17, '2026-10-02'), (5, 27, '2026-10-03'), (1, 27, '2026-10-04'), (6, 17, '2026-10-05')"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Save: read them back
sql "SELECT * FROM requests"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Lab job 2: search
To search is to find the data you want. WHERE keeps only the rows that match. Which products are sold out? A stock of 0 means none left.
Extra: Search: sold out products
sql "SELECT id, name, stock FROM products WHERE stock = 0"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Lab job 5: organise with an index
Think of the index at the back of a book. You do not read every page. You look up a word and go to the page.
A database index works the same. With an index on asked_on, the database finds a date without reading every row. With 5 rows you will not notice. With 5 million rows you will.
Extra: Organise: make an index
sql "CREATE INDEX idx_requests_date ON requests (asked_on)"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: See the index
sql "SHOW INDEX FROM requests"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Lab jobs 4, 6, 7: integrate, output, feedback
The requests hold only numbers. The names are in other tables. A join puts them together. That is integrate.
The next command counts the requests for each product, biggest first. That is output.
The teapot was asked for 3 times. So the shop buys 20 teapots. The last two commands change the stock and check it. That is the feedback loop.
Extra: Integrate: names beside requests
sql "SELECT customers.first_name, products.name, requests.asked_on FROM requests JOIN customers ON customers.id = requests.customer_id JOIN products ON products.id = requests.product_id ORDER BY requests.asked_on"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Output: count the asks
sql "SELECT products.name, COUNT(*) AS asks FROM requests JOIN products ON products.id = requests.product_id GROUP BY products.name ORDER BY asks DESC"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Feedback: stock 20 teapots
sql "UPDATE products SET stock = 20 WHERE id = 17"A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Check the new stock
sql "SELECT id, name, stock FROM products WHERE id = 17"A command for the lesson’s lab terminal. It is shown here and not run.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go
Final check
5 questionsRemember
Important
A data system does seven jobs: input, search, save, integrate, organise with an index, output, and a feedback loop. Name the job when you see it.