Application Fundamentals
RecruitCode / policy labScenario sim

Databases for Applications

Trace application data through keys, queries and transactions, then defend database access, recovery and audit evidence.

50 min 135 XPSkills: Data modeling, SQL reasoning, Database controls

Brief

At Halcyon Clinics, a booking service reports a confirmed appointment even though its room reservation failed. A support analyst exports every patient column to find the problem, using the same powerful database account as the application. The operations lead says a nightly backup and a fast query prove the system is safe. Neither claim addresses the broken booking or the unnecessary disclosure.

You will follow one booking from its data model to its recovery evidence. The goal is to distinguish a relationship from an index, a filtered result from an access boundary, and a completed backup from a tested restoration. These distinctions determine whether the clinic can preserve accurate records, restrict access and explain a failure to an auditor.

A database control needs an enforceable mechanism and observable evidence: a promise in application code is not a substitute for database constraints, grants or restore tests.

Model relationships before writing queries

A relational model stores rows in tables with defined columns and constraints. Consider patients(patient_id, name) and appointments(appointment_id, patient_id, status). Each table's primary key is unique and non-null; appointments.patient_id is a foreign key referencing patients.patient_id. A required foreign key also needs a non-null constraint: otherwise a null value can represent an unassigned relationship. A foreign key prevents a reference to a nonexistent patient; it does not automatically authorize the person reading that patient's records.

A document model groups fields and nested collections into documents. Embedding a booking's small, bounded list of preparation instructions makes one-document reads convenient. Embedding a patient's name into 200 independent booking documents duplicates it, so a name correction requires coordination or an explicitly accepted stale snapshot. Document databases can enforce validation and may support multi-document transactions; relational databases can also store nested data. Choose boundaries based on update consistency, relationships and access patterns, not a claim that one model has no schema.

For integrity assurance, preserve schema definitions, relationship constraints and rejected-write test results. An auditor can ask whether an appointment with patient_id 999 is rejected when that patient does not exist. A diagram alone documents intent; the enforced constraint and its test demonstrate operation.

Two table boxes show patients with primary key patient_id and appointments with primary key appointment_id and foreign key patient_id. Patient 42 connects to appointments 701 and 702 through a one-to-many arrow. A crossed-out appointment 703 references nonexistent patient 999, labelled rejected foreign key.
Keys identify rows and constrain references; they do not grant permission to read them.

Read a query and its access path

SELECT chooses result columns; WHERE filters rows; JOIN combines matching rows. In SELECT a.appointment_id, p.name FROM appointments a JOIN patients p ON a.patient_id = p.patient_id WHERE a.status = 'confirmed', the aliases identify each table and the ON expression matches its relationship. With patients 42 and 43 and confirmed appointments 701 and 702 both for patient 42, the result contains two rows, not one patient row. An inner join omits unmatched rows; a left join retains left-side rows with null right-side fields. Joining without the relationship predicate can multiply rows and corrupt evidence counts.

An index is an additional lookup structure, commonly an ordered tree, which can reduce rows examined. An index on (patient_id, status) often helps queries constrained by patient_id and then status; a status-only query may not benefit the same way. On a million-row table, a selective lookup might inspect tens of matches rather than scanning every row. The optimizer still chooses a plan based on statistics and estimated cost. Indexes consume space and add work to inserts, updates and deletes; an ordinary index does not enforce referential integrity or uniqueness.

Use bound query parameters for untrusted values rather than concatenating text into SQL. A WHERE clause requesting one clinic's rows is not a permission boundary if callers can alter the query. Review grants and any database-enforced row policies separately. For evidence queries retain the query, parameters, collection time and row-count reconciliation; inspect the execution plan before adding indexes solely because a report is slow.

Transactions protect a business change

Treat creating appointment 701 and reserving its room as one transaction: begin, perform both writes, then commit only if both succeed; otherwise roll back. Atomicity means all-or-nothing for that transaction. Consistency means declared invariants remain satisfied when valid transactions run; it does not mean the database knows every business rule. A unique constraint on a room and time slot can reject a duplicate reservation that application-only prechecks miss.

Isolation controls what concurrent transactions observe. Two requests can both read an available slot before either writes; a transaction alone does not guarantee that arbitrary read-then-write logic is race-free. Appropriate constraints, locking or stronger isolation are needed, with retry handling for conflicts. Durability means acknowledged committed changes survive failures under the database's configured guarantees. Confirm persistence and replication settings rather than assuming a successful response proves resilience to every disaster.

Together these properties form ACID: atomicity, consistency, isolation and durability. Integrity evidence includes transaction boundaries, constraint definitions and concurrent booking tests showing that only one contender succeeds. Ask which invariant was tested, which isolation behavior was configured and whether error handling can accidentally commit partial work. A fast index is no evidence that the two writes commit together.

Limit access and prove recovery

Give the booking runtime a dedicated account with only required operations on required tables; keep schema-changing migration credentials separate and time-limited. A reporting account may need SELECT on a restricted view, not write access or all patient fields. Review effective privileges, including inherited roles, and test denied operations. Protect connections with TLS and keep credentials out of source files. Least privilege limits impact even when a query or application is compromised.

A backup is a recoverable copy, not evidence that recovery works. A daily base backup plus continuous transaction-log archival can support point-in-time recovery: restore the base, then replay the unbroken log chain to a selected time before a destructive commit. If deletion commits at 14:07, test recovery to 14:06 in an isolated environment. An RPO of five minutes limits acceptable lost committed work; an RTO of 60 minutes limits restoration duration. Measure both in restore drills, verify record integrity, protect backup keys and retain copies outside the application's deletion authority. A replica can repeat an accidental deletion and is not a replacement for independent recovery copies.

Database audit logs should record relevant authentication, privilege changes and sensitive data access with timestamp, actor, action, object and outcome. Restrict and centralize them so the runtime account cannot erase its own trail; avoid recording secrets or unnecessary patient values. Transaction logs used for replay are not automatically a human-readable access audit. Auditors need effective grant exports, restore-test timelines and protected audit events tied to the review period, not just a green backup-job status.

A timeline starts with a 00:00 base backup followed by sequential archived transaction-log segments. A restore arrow replays segments to 14:06 and stops before a red destructive commit at 14:07. A separate isolated recovery box shows record validation and a stopwatch labelled RTO 60 minutes, beside RPO five minutes.
Point-in-time recovery needs a usable base, an intact log chain and a tested stopping point.

Tasks

Answers are graded on the server: the answer key never reaches your browser.

Task 1: A faster orphan

Scenario sim+45 XP

Read the brief and answer both questions.

Incident brief

Appointments reference patient identifiers that do not exist. The engineer proposes an ordinary non-unique index, calling it a relationship control. The existing appointment_id column must uniquely identify every appointment; patient_id must reference an existing patient. Neither requirement is currently enforced.

Term bank, not all of these are right

foreign keyprimary keyordinary indexaudit log

1.1Which key should enforce the reference from appointments to patients? (two words)

1.2Which key should identify each appointment row uniquely and disallow nulls? (two words)

Task 2: One booking, half a change

Scenario sim+45 XP

Read the brief and answer both questions.

Incident brief

Creating an appointment succeeds, but inserting its room reservation fails. The developer independently commits both statements and calls the outcome an isolation failure. Separately, a report must return only confirmed appointments; a colleague proposes SELECT as the clause that filters rows.

Term bank, not all of these are right

atomicityWHEREisolationSELECT

2.1Which ACID property is missing from the two-write business operation? (one word)

2.2Which SQL clause should filter the report by status? (one word)

Task 3: Recovery is not a screenshot

Scenario sim+45 XP

Read the brief and answer both questions.

Incident brief

An approved recovery policy allows at most five minutes of lost committed work and 60 minutes to restore service. The manager labels the five-minute limit RTO. A nightly base backup and continuous archived transaction logs have passed an isolated replay test, so the team can stop just before a deletion rather than recover only last night's state.

Term bank, not all of these are right

RPOPITRRTOACID

3.1Which metric names the five-minute allowable data-loss limit? (three-letter abbreviation)

3.2Which recovery method replays the logs to the chosen instant before deletion? (four-letter abbreviation)

Labs

80 bonus XP

Hands-on work. You edit the artefact, the server runs the checks: the expectations and the reference solution never reach your browser.

Lab 1 · YAML lab

Constrain the booking service and its recovery

Briefing 40 XP

Halcyon Clinics needs a machine-readable database control plan. The service owner suggests sharing the migration administrator account and says nightly backups meet every recovery target. Translate the requirements beside the editor into explicit fields rather than accepting either shortcut.

Use YAML booleans for switches, numeric minutes for objectives and a list for audit event categories. This is a plan, not a live configuration: grants, log collection and replay capability still need implementation and testing against the database.

Approved booking-service requirements

Runtime account: booking_runtime; never shared with migrations.
Allowed runtime operations on appointments: SELECT, INSERT, UPDATE only.
Runtime schema changes: prohibited.
Recovery objectives: RPO exactly 5 minutes; RTO exactly 60 minutes.
Recovery source: daily base backup plus continuous transaction-log archival.
Required recovery capability: restore to an instant before a destructive commit.
Required verification: isolated restore test.
Audit categories: authentication, privilege_change, sensitive_read.
Audit destination: protected central collector, outside runtime deletion authority.

Checks

  • Dedicated runtime identity and no schema changes
  • Runtime operations match the approved set
  • Data-loss and restoration objectives stay distinct
  • Backup and log strategy supports a selected recovery instant
  • Recovery is verified in isolation
  • Required audit events are protected from runtime deletion
Lab 2 · Review lab

Review six database control claims

Briefing 40 XP

The clinic's release lead calls all six claims audit-ready because each came from a successful deployment. Review the actual mechanisms and test evidence, not that label.

Accept supported claims. Reject each unsupported claim with its single root-cause code: relationship-gap for missing reference enforcement, excessive-privilege for unnecessary authority, unproven-recovery for absent restoration evidence, or audit-gap for a trail the monitored account can erase. Leave accepted reasons empty.

Verdicts are accept or reject. Every rejection needs one reason code from: relationship-gap | excessive-privilege | unproven-recovery | audit-gap.

Release evidence ledger

DBA-1 | appointments.patient_id is required and has an enforced foreign key to patients.patient_id; an orphan insert test fails as intended.
DBA-2 | A non-unique index on appointments.patient_id is the only relationship mechanism; the lead says it prevents orphan records.
DBA-3 | The reporting runtime needs SELECT on a restricted view but also receives database-wide write and schema-change permissions for convenience.
DBA-4 | Daily backup jobs succeed; no restoration has ever been attempted. The lead claims the 60-minute restoration objective is proven.
DBA-5 | Authentication, privilege changes and sensitive reads are audited, but the runtime account can delete the only stored event copies.
DBA-6 | An isolated drill restored a base backup and replayed the complete archived log chain to before a deletion; integrity checks passed, measured loss was 2 minutes and recovery took 38 minutes against 5-minute and 60-minute targets.

Checks

  • Every line in the fixture carries a verdict
  • Accept and reject land on the right lines
  • Each rejection cites a valid reason code

Next on your path · Application Fundamentals

Authentication and Authorisation in Apps

Trace identity from password verification to delegated tokens, then enforce access on every object request.

Analyst 55 min 180 XP
Start next room

Community

Discussion & writeups

Sign in to post

Share how you approached the room or ask where you got stuck. Never paste task answers or full lab solutions: write the reasoning, not the key.

Loading discussion…