Notebook · Notebook without plots · Python · Python without plots
How to model server-to-server interaction
A user action can trigger work on several services: the web application may call a database, which may call another backend. Include the downstream work when describing the action, even when the user's device never contacts it directly.
Load the full e-commerce scenario.
Describe all work triggered by the action
List the direct and transitive jobs on the upstream UsageJourneyStep. Each job points to the server that performs it. This describes the work caused by one occurrence of the step; it does not execute live service requests.
For example, browsing a catalogue triggers a web job and a database query.
Both belong to the browse step. If an action triggers several different queries,
include each query job. For repeated calls to the same operation, jobs accepts
a mapping from each job to its dimensionless SourceValue call count. A plain
list gives each listed job one occurrence.
Reuse a job object across steps when its per-call resource needs are the same. Sharing its definition keeps those inputs in one place; each triggering step still contributes its own executions. Likewise, pass the same server object to jobs that share hardware rather than creating a new server for every call.
Work through a web request and its database query
The example first defines the database and application jobs, then connects them
in journey steps. In browse_step, serve_catalog and read_catalog describe
the two services involved in one action. Cart and checkout work follow the same
pattern. Their transferred data and retained data are separate inputs.
The setup uses the same on-premise database and autoscaling web server as the complete tutorial. See the database guide for engine, storage and query assumptions. The cells below include their setup so you can run the example in order.
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:20,837 - INFO - Imported BoaviztaCloudServer in 0.03396 seconds.
from efootprint.core.usage.usage_journey import UsageJourney
from efootprint.core.usage.usage_journey_step import UsageJourneyStep
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))
Model the web application
Now we can describe the application tier with the same building blocks: storage,
a server, and jobs. The important change is ServerTypes.autoscaling(). Its
instance count follows demand in whole instances, whereas our database remains
provisioned for the period.
We are still describing what the service needs, without giving it any traffic. The usage patterns later in the tutorial will provide the demand used for sizing.
web_storage = Storage.from_defaults(
"Web app local storage", base_storage_need=SourceValue(1 * u.GB_stored))
web_server = BoaviztaCloudServer.from_defaults(
"Web application server", server_type=ServerTypes.autoscaling(),
provider=SourceObject("scaleway"),
instance_type=SourceObject("ent1-s"),
base_ram_consumption=SourceValue(4 * u.GB_ram),
base_compute_consumption=SourceValue(0.2 * u.cpu_core),
average_carbon_intensity=SourceValue(100 * u.g / u.kWh),
storage=web_storage)
Describe web requests
Use the same Job structure for application requests. Each job below describes
the web server's part of an action; its database query remains a separate job.
For example, the catalogue response payload is an application input we can later
change to explore a design alternative.
serve_catalog = Job(
"Serve catalog page", server=web_server,
request_duration=SourceValue(120 * u.ms),
compute_needed=SourceValue(0.1 * u.cpu_core),
ram_needed=SourceValue(80 * u.MB_ram),
data_transferred=SourceValue(1.5 * u.MB),
data_stored=SourceValue(0 * u.kB_stored))
update_cart = Job(
"Update cart", server=web_server,
request_duration=SourceValue(60 * u.ms),
compute_needed=SourceValue(0.05 * u.cpu_core),
ram_needed=SourceValue(40 * u.MB_ram),
data_transferred=SourceValue(30 * u.kB),
data_stored=SourceValue(0 * u.kB_stored))
submit_order = Job(
"Submit order", server=web_server,
request_duration=SourceValue(200 * u.ms),
compute_needed=SourceValue(0.15 * u.cpu_core),
ram_needed=SourceValue(120 * u.MB_ram),
data_transferred=SourceValue(80 * u.kB),
data_stored=SourceValue(0 * u.kB_stored))
Connect web and database jobs
We have described individual operations. To represent what happens when someone
uses the service, put the relevant jobs into a UsageJourneyStep.
Browsing the catalogue triggers both serve_catalog and read_catalog, so they
belong to the same step. The other steps pair a web request with its database
write in the same way. Passing the existing job objects connects their work;
there is no need to recreate the database server or a separate database journey.
browse_step = UsageJourneyStep.from_defaults(
"Browse the catalog", jobs=[serve_catalog, read_catalog])
cart_step = UsageJourneyStep.from_defaults(
"Add an item to the cart", jobs=[update_cart, write_cart])
checkout_step = UsageJourneyStep.from_defaults(
"Check out", jobs=[submit_order, write_order])
Assemble the shopping journey
A UsageJourney groups these steps into one visit. With this list, each step
occurs once per journey. We can reuse that journey for different populations
without recreating its jobs or hardware.
Choose useful modeling granularity
The resulting journey connects work to infrastructure. A usage pattern will provide its volume; the complete tutorial continues with that step and result inspection.
Start with enough detail to capture the important contributors and the changes you want to compare. Several small operations can be represented by one aggregate job when that preserves the relevant resource use. Split them when their costs, call counts or behavior differ in a way that affects the result. The methodology explains this iterative approach.
Pitfalls
- Missing fan-out. One frontend action may trigger several backend calls. Counting only the user-facing job omits that work.
- Counting an aggregate and its parts. If one job already includes downstream resource use, listing those same operations separately counts them again. Choose one representation for each piece of work.
- Duplicating shared hardware. Separate servers represent separate hardware resources. Reuse the server when several jobs run on the same infrastructure.
- Confusing reuse with frequency. Reusing a job does not combine all its calls into one occurrence. Check its count in each triggering step, especially when a request repeats the same query.
Continue with the complete tutorial to add demand and inspect the model's footprint.