Skip to content

Notebook · Notebook without plots · Python · Python without plots

How to model a database

A database combines a Server, persistent Storage and one Job for each kind of query. e-footprint has no separate database abstraction: describe the engine's standing needs, the data it keeps and the operations it performs with these primitives.

Load the full e-commerce scenario.

Choose the database inputs

  • Engine baseline. Put the resources held independently of queries in base_ram_consumption and base_compute_consumption. Include buffer pools, connection workers and background tasks such as checkpointing and autovacuum. Both inputs default to zero; an idle database can still need them.
  • Persistent data. Set base_storage_need to the existing tables and indexes at the start of the modeled period, including their replicas. Check data_storage_duration against your retention policy and data_replication_factor against the replica count for job-driven growth; that factor does not multiply the baseline again. Storage accounts for its hardware manufacturing and operating energy; counting those volumes again on the server double-counts them.
  • Each operation type. Describe the CPU and RAM occupied by one query with compute_needed and ram_needed, for its request_duration. Separate the network payload, data_transferred, from the net durable growth, data_stored. A write can transfer data and add stored data in the same call; a read usually adds none.

Run the worked example

Install efootprint. Hardware sizing uses the Boavizta API; efootprint[boaviztapi] adds an offline fallback.

The example models catalogue reads, cart writes and order writes as separate jobs. Replace its illustrative assumptions with measurements for your engine and queries, citing a Source on the inputs. Check retention and replication defaults against your deployment.

from efootprint.abstract_modeling_classes.source_objects import SourceObject, SourceValue
from efootprint.builders.hardware.boavizta_cloud_server import BoaviztaCloudServer
from efootprint.constants.units import u
from efootprint.core.hardware.server_base import ServerTypes
from efootprint.core.hardware.storage import Storage
from efootprint.core.usage.job import Job
2026-12-01 12:18:19,761 - INFO - Imported BoaviztaCloudServer in 0.03566 seconds.

Model the database

Let's start with the hardware that holds the product data. Storage describes the persistent data, while the server describes the machine running the engine. Passing storage=db_storage connects these objects: it is the storage attached to this server, rather than a second independent copy.

Storage.from_defaults fills unspecified inputs with defaults and lets us override the starting amount of data. BoaviztaCloudServer.from_defaults also uses a provider and instance type to obtain a reference hardware profile. Here that profile is a sizing proxy for an on-premise database. on_premise() keeps its provisioned capacity available throughout the modeled period.

The engine's background RAM and CPU needs are separate from the work of queries. Idle power defaults to zero in this example; replace that assumption with a measurement when accounting for idle electricity. Storage accounts for its own hardware and energy, so those volumes should not be counted again on the server.

db_storage = Storage.from_defaults(
    "Product database storage", base_storage_need=SourceValue(200 * u.GB_stored))
db_server = BoaviztaCloudServer.from_defaults(
    "Product database server", server_type=ServerTypes.on_premise(),
    provider=SourceObject("scaleway"),
    instance_type=SourceObject("ent1-l"),
    base_ram_consumption=SourceValue(2 * u.GB_ram),
    base_compute_consumption=SourceValue(0.1 * u.cpu_core),
    average_carbon_intensity=SourceValue(100 * u.g / u.kWh),
    storage=db_storage)

Describe query work

A Job describes one execution of an operation and links it to the server doing the work. Duration says how long its CPU and RAM are occupied. Data transferred is the network payload; data stored is the net addition to persistent data.

Keep reads, cart writes and order writes as separate jobs so their different resource needs and data growth remain visible. At this stage we describe the cost of one operation. The journey and demand will tell us how often it happens.

read_catalog = Job(
    "Read product catalog", server=db_server,
    request_duration=SourceValue(20 * u.ms),
    compute_needed=SourceValue(0.1 * u.cpu_core),
    ram_needed=SourceValue(20 * u.MB_ram),
    data_transferred=SourceValue(5 * u.kB),
    data_stored=SourceValue(0 * u.kB_stored))

write_cart = Job(
    "Write cart row", server=db_server,
    request_duration=SourceValue(40 * u.ms),
    compute_needed=SourceValue(0.2 * u.cpu_core),
    ram_needed=SourceValue(50 * u.MB_ram),
    data_transferred=SourceValue(2 * u.kB),
    data_stored=SourceValue(2 * u.kB_stored))

write_order = Job(
    "Write order row", server=db_server,
    request_duration=SourceValue(80 * u.ms),
    compute_needed=SourceValue(0.25 * u.cpu_core),
    ram_needed=SourceValue(80 * u.MB_ram),
    data_transferred=SourceValue(8 * u.kB),
    data_stored=SourceValue(10 * u.kB_stored))

Pitfalls

  • Averaging different operations. A single average of reads and writes hides their different compute needs and durable data growth. Give distinct operation types their own jobs and represent their frequencies in the usage journey.
  • Mixing transfer with storage. A response payload is network traffic; only the net data retained by the database contributes to durable storage growth. Repeated reads do not store another copy of the result on each call.
  • Omitting background engine needs. A quiet database still needs RAM and CPU. The zero baseline defaults omit those standing needs.

The server-to-server guide connects these jobs to the calling web application.

Continue with the complete tutorial to add demand and inspect the model's footprint.