Week 9

Types of Databases

Databases: Comparison, Choosing & Polyglot

jsonb: Concepts & Setup

jsonb: querying updating

jsonb: Indexes, Tradeoffs & Exercise

Object Storage

Practice

Assignment

Backend Track

Content

Let’s get practical

<aside> 🚧

This page is currently under construction. Please check back later.

</aside>

Exercises

πŸ’­ Practice exercises are optional and do not need to be submitted.

For all exercises, use a small Spring Boot project with Spring Web, JDBC API, PostgreSQL Driver, Lombok, and Jackson Databind. You may create a fresh project for each exercise, or keep each exercise in its own feature package inside one practice project.


Exercise 1 β€” Design a jsonb Schema

Choose a resource that has varying attributes per item type. Good candidates:

Create a markdown file named SCHEMA_DESIGN.md and design a jsonb-backed table for your resource.

Requirements:

Reflection questions:

  1. Which fields did you put in normal columns and which in jsonb? What was your reasoning?
  2. If your most common query filters by a JSON field β€” should that field stay in jsonb or become a proper column?

Exercise 2 β€” Build a jsonb API

Choose one of these resources:

Build a Spring Boot REST API backed by PostgreSQL with a jsonb column.

Requirements:

Method Endpoint What it does
GET /api/{resource} Get all records
POST /api/{resource} Add a new record
GET /api/{resource}?field=value Filter by a JSON field using ->>
GET /api/{resource}/search?a=x&b=y Filter by multiple JSON fields using @>
PATCH /api/{resource}/{id}/field?value=x Update one JSON field using jsonb_set

Reflection questions:

  1. What happens when you query details->>'field' for a row that does not have that field? Test it and explain the result.
  2. You used @> to match multiple fields. What would break if you tried to do the same thing with >> and WHERE clauses?

Exercise 3 β€” Upload and Retrieve a File

Set up Backblaze B2 and connect it to a Spring Boot project. Build a minimal file API with three endpoints.

Setup (do this first):

Follow the Backblaze B2 Setup Guide to:

Requirements:

Build these three endpoints:

Method Endpoint What it does
POST /api/files/upload Upload a file β€” returns the object key
GET /api/files/link?key=... Returns a presigned URL valid for 15 minutes
DELETE /api/files?key=... Deletes the file from the bucket

Reflection questions:

  1. You uploaded a file and got back a key. In a real application, where would you store this key?
  2. What is the difference between using a presigned URL vs making the bucket public? When is each appropriate?
  3. What happens if you try to use a presigned URL after it has expired?

The HackYourFuture curriculum is licensed underΒ CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❀️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.