We are building an SLO (Service Level Objective) budgeting simulator. The goal is to allow engineering leaders to explore trade-offs between roadmap projects, hiring, and tech debt remediation.
The core idea:
We have a set of services with current SLOs (error budgets) and capacity (in terms of team or person-hours).
The leader can allocate the error budget (or capacity) to different types of work: new features (roadmap), hiring, and tech debt remediation.
Each type of work consumes some of the error budget and affects the SLOs in different ways.
However, note that error budget is typically about reliability (how much downtime or errors you can afford). But in the context of capacity planning, we might think of "capacity" as the amount of work that can be done without burning out the team or without increasing the error budget consumption.
Alternatively, we can think in terms of "capacity" (in person-hours per week) and then map that to the error budget consumption. But note that the problem says "SLO budgeting", so we are using the error budget as a resource to allocate.
Let's define:
Total error budget for a service: usually a percentage (e.g., 99.9% uptime means 0.1% error budget). But for planning, we might think in terms of "how much of the error budget we are willing to spend on changes".
However, note that the error budget is consumed by incidents (unplanned work) and also by planned work that might cause disruptions (deployments, etc.).
Alternatively, we can think of the error budget as a constraint: we cannot spend more than the error budget on planned work that might cause outages.
But the problem is about trade-offs: if we spend more on roadmap (which might be risky and consume error budget), then we have less for tech debt remediation (which might reduce future error budget consumption) and hiring (which might increase capacity).
Actually, the problem might be mixing two concepts:
1. Error budget (for reliability)
2. Team capacity (for work)
Let me re-read: "SLO budgeting simulator" and "roadmap trade-offs, hiring, and tech debt remediation".
I think we are to simulate the allocation of a fixed resource (which could be either error budget or team capacity) to different types of work, and see the effect on the SLOs and on the team's ability to deliver.
Let's assume we are given:
- A set of services, each with:
* current error budget consumption (or remaining error budget)
* current capacity (team size or person-hours)
We are going to plan for a time period (e.g., a quarter).
The leader can:
- Assign some of the capacity to roadmap projects (which will consume some of the error budget because they are changes that might cause incidents)
- Assign some to hiring (which will increase capacity in the future, but might temporarily reduce capacity because of onboarding)
- Assign some to tech debt remediation (which will reduce the error budget consumption of the service in the future, because the service becomes more reliable)
We need to model:
- How each type of work affects the current error budget and capacity.
- The trade-offs: if we do more roadmap, we might consume more error budget and risk burning through it. If we do more tech debt, we reduce future error budget consumption but delay roadmap.
We need to define:
code
For each service:
Let:
E_budget = total error budget for the period (e.g., 0.1% of total time in the period). But note: error budget is usually a percentage of time, so for a quarter we can compute the allowed downtime minutes.
However, it might be easier to think in terms of "error budget points" or "units" that we can allocate.
Alternatively, we can think of the error budget as a constraint: the total planned work that might cause errors (roadmap and tech debt? but tech debt is supposed to reduce errors) cannot exceed the error budget? Not exactly.
Actually, the error budget is for unplanned errors. But planned work (like deployments) can also cause errors and should be counted against the error budget.
So, let's define:
Let:
Current_error_budget_consumption = how much of the error budget is already used by existing incidents (unplanned) and by the current state of the service (maybe based on current SLO compliance).
Then, when we do a roadmap project, we expect it to cause some additional errors (or downtime) because of deployment issues, bugs, etc. So we set a risk factor for each project: e.g., a project might have a 10% chance of causing an incident that consumes X units of error budget.
Similarly, tech debt remediation might also cause temporary issues but then reduce the error rate.
However, for simplicity, we can assume:
- Roadmap projects: consume a fixed amount of error budget (or a random amount with an expected value). We can let the user set the expected error budget consumption for each project.
- Tech debt remediation: reduces the base error rate of the service, so in the future the same amount of work (or even more) will consume less error budget.
- Hiring: increases the capacity (so we can do more work) but might temporarily reduce capacity because of the time spent onboarding.
We need to model over time. Let's say we are planning for 4 quarters.
We can have:
code
For each service, at each quarter t:
- Starting error budget remaining (from previous quarter)
- Starting capacity (person-hours per week)
Then we allocate the capacity to:
- Roadmap: we choose a set of projects. Each project has:
* required_capacity (person-hours)
* expected_error_budget_consumption (units)
* value (maybe in terms of business value, but we don't necessarily need that for the simulation, unless we want to optimize)
- Tech debt: we choose a set of tech debt tasks. Each task has:
* required_capacity
* expected_error_budget_reduction (per quarter in the future) - this could be a reduction in the base error rate of the service.
- Hiring: we decide how many engineers to hire. Each new hire:
* takes some capacity (from existing team) for onboarding (say 2 months of reduced capacity from the existing team to mentor)
* after onboarding, adds full capacity.
Then we compute:
- Total capacity used by roadmap and tech debt must be <= available capacity (after accounting for hiring and onboarding).
- The error budget consumption for the quarter = current base error rate * (time period) + sum of error budget consumption from roadmap projects.
But note: the base error rate might change due to tech debt from previous quarters.
Then we check if the total error budget consumption exceeds the allocated error budget for the quarter? Actually, the error budget is for the entire period? Typically, SLOs are measured over a rolling window (e.g., 30 days). So we might need to simulate a rolling window.
However, for simplicity, we can assume that the error budget is per quarter and we carry over the remaining error budget to the next quarter? Not typically, because error budget is usually a rolling window. But for planning, we can set a quarterly error budget target.
Alternatively, we can think of the error budget as a fixed amount per quarter (e.g., 0.1% of the quarter's total seconds). Then we have:
Quarterly_error_budget = (total_seconds_in_quarter) * (1 - SLO_target)
And we must keep the error consumption (from incidents and risky changes) within that.
But note: if we do tech debt, we reduce the base error rate, so the natural consumption (without any incidents) will be lower.
Let's define:
code
For each service:
base_error_rate (per second) -> this is the current error rate without any incidents? Actually, the base error rate is the rate at which the service fails even without any changes.
Then, over a quarter (T seconds), the expected error seconds without any incidents = base_error_rate * T.
Plus, each roadmap project adds expected_error_seconds.
So total expected error seconds for the quarter = (base_error_rate * T) + sum(project_expected_error_seconds)
We want this to be <= Quarterly_error_budget.
But note: the base_error_rate can be reduced by tech debt.
How does tech debt affect base_error_rate?
We can model: base_error_rate = initial_base_error_rate - sum(tech_debt_reductions from previous quarters that are still effective)
But tech debt reductions might be permanent? Or they might decay? Let's assume they are permanent until the service is re-architected again.
So, we can have:
base_error_rate_q0 = initial_base_error_rate
For q in 1..4:
base_error_rate_q = base_error_rate_{q-1} - sum of tech_debt_reductions done in q-1 and earlier that are still effective.
However, note that tech debt reductions might take effect immediately? Or after the project is done? Let's assume they take effect in the next quarter.
Steps for simulation:
code
Implementation:
code
However, we might want to have a way to set the mentor time per hire and the full capacity per hire as parameters.
Also, we might want to have a way to set the seconds in a quarter (maybe 90 days, or exact days?).
Let's adjust:
code
In ServiceSimulator, we can have:
__init__(self, service_name, initial_capacity, initial_base_error_rate, quarterly_error_budget,
mentor_hours_per_hire=80, full_capacity_per_hire_hours_per_quarter=520):
Then in simulate_quarter, we use these.
Now, the user interface:
code
We want to allow the leader to explore trade-offs. So we need to let them set:
For each service and for each quarter (for 4 quarters):
- How many hires?
- Which roadmap projects (from a list of available projects) and how much capacity to allocate to each? But note: a project might require a fixed capacity? Or we can allocate partial?
We can let the user define:
A list of possible projects for each service, each with:
name, required_capacity, expected_error_seconds
And then the user can select a subset and assign the required capacity? But what if they want to do a project partially? Then we need to allow scaling.
Similarly for tech debt tasks.
Alternatively, we can let the user set:
For each service, for each quarter:
- total capacity to allocate to roadmap (and then we have a list of projects with priorities? and we allocate in order until capacity is exhausted?)
But the error budget constraint is per project? Or we can have a total expected error from roadmap.
Given the complexity, let's assume:
We have a fixed set of projects and tech debt tasks for each service. The user can choose which ones to do in which quarter, and they must be done fully (cannot partially).
Then, the user's allocation for a service in a quarter is:
- A list of project names to do (from the available projects for that service)
- A list of tech debt task names to do
- Number of hires
Then we look up the required capacity and expected error seconds for each project and task.
We can have:
ServiceSimulator has a list of available projects and tech debt tasks? Or we pass them in each quarter?
Let's change:
We'll have:
class ServiceSimulator:
def __init__(self, ...):
...
self.available_projects = [] # list of project dicts
self.available_tech_debt = [] # list of tech debt task dicts
def add_project(self, project):
self.available_projects.append(project)
def add_tech_debt(self, task):
self.available_tech_debt.append(task)
Then in simulate_quarter, we pass:
project_names: list of names of projects to do this quarter
tech_debt_names: list of names of tech debt tasks to do this quarter
hires: integer
Then we look up the projects and tasks by name.
But note: a project might be done over multiple quarters? Then we would need to allow partial allocation?
Alternatively, we can let the user define the projects with a required_capacity and then they can assign that capacity over multiple quarters? But then the error budget consumption might be in the quarter when the project is deployed? Or spread?
This is getting too complex.
Let's stick to: each project is done in one quarter and consumes its full capacity and error budget in that quarter.
Similarly for tech debt.
Now, we need to think about the output:
code
We want to show the leader the trade-offs. So we can show:
For each service and each quarter:
- Capacity used for roadmap, tech debt, and mentoring.
- Error budget consumption and remaining.
- Capacity and base error rate for next quarter.
And we can also show the cumulative effect.
We can also have a summary for the organization.
Implementation:
code
We'll create:
class Project:
def __init__(self, name, capacity, expected_error_seconds):
self.name = name
self.capacity = capacity
self.expected_error_seconds = expected_error_seconds
class TechDebtTask:
def __init__(self, name, capacity, error_rate_reduction):
self.name = name
self.capacity = capacity
self.error_rate_reduction = error_rate_reduction
class Hire:
def __init__(self, mentor_time_per_week=10, full_capacity_per_quarter=520):
self.mentor_time_per_week = mentor_time_per_week
self.full_capacity_per_quarter = full_capacity_per_quarter
But note: we are not using the Hire class in the ServiceSimulator above, because we just pass an integer for number of hires.
Alternatively, we can have:
In ServiceSimulator, we have parameters for mentor_hours_per_hire and full_capacity_per_hire_hours_per_quarter.
So we don't need a Hire class.
Let's code accordingly.
However, note: the mentor time is per week and the full capacity per quarter. We can compute:
code
Let's code accordingly.
However, we might want to make the mentor_hours_per_hire and full_capacity_per_hire configurable per service? Probably not, they are organization-wide.
Now, what about the base error rate? We are reducing it by the error_rate_reduction of the tech debt tasks done in this quarter, and that reduction takes effect next quarter.
But what if we do multiple tech debt tasks that reduce the same error? We just subtract all.
Now, let's think about the error budget:
code
We have quarterly_error_budget in seconds.
We compute:
base_error_seconds = self.base_error_rate * seconds_in_quarter
But note: the base_error_rate is in errors per second. So if we have a service that is up 99.9% of the time, then base_error_rate = 0.001 (per second)? Actually, 99.9% uptime means 0.1% error, so error rate = 0.001 per second? Not exactly, because error rate is the probability of an error at any given second? Usually, SLO is about the fraction of time the service is available. So if we have 99.9% availability, then the error rate (or down rate) is 0.001, meaning 0.1% of the time the service is down.
But then base_error_seconds = 0.001 * seconds_in_quarter.
That matches.
Now, we need to define the available projects and tech debt tasks for each service.
Then the simulator will look up the projects and tech debt by name and use their capacity and error metrics.
Now, let's write a function to run a simulation for an organization for 4 quarters.
We'll have:
code
Now, we can set up the organization and run 4 quarters.
Example:
code
services_config = [
{
'service_name': 'Service A',
'initial_capacity': 1000, # 1000 person-hours per quarter? That's about 2 engineers? (520*2=1040) so roughly 2.
'initial_base_error_rate': 0.001, # 0.1% error rate
'quarterly_error_budget': 0.001 * 90 * 24 * 3600 # 0.1% of 90 days in seconds.
},
...
]
Then add projects and tech debt.
Then for each quarter, we set:
quarter_allocations = {
'Service A': {
'project_names': ['Project1', 'Project2'],
'tech_debt_names': ['Task1'],
'hires': 1
},
...
}
Then run simulate_quarter for each quarter.
We can then generate a report and plot.
This is a simplified model. In reality, we would have more constraints and more complex interactions.
But for a simulator to explore trade-offs, this might be a good start.
Let's code accordingly.
However, note: the error budget is per service and we are not sharing error budget across services. But in reality, we might have an organization-wide error budget? Or per service.
We are doing per service.
Now, we need to think about the UI. The problem says "engineer an SLO budgeting simulator", so we are building the backend logic. The UI can be built on top.
We'll provide:
code
- A way to define services (with initial capacity, base error rate, and SLO target to compute quarterly_error_budget? or directly quarterly_error_budget).
- A way to define projects and tech debt tasks for each service.
- A way to set quarterly allocations (for 4 quarters) and run the simulation.
- A report (text or chart) showing the evolution of capacity and error budget.
We can also add:
code
- The ability to see the impact on the SLO (if we exceed the error budget, we are below the SLO).
But note: the error budget is the allowed error. If we exceed, then we are not meeting the SLO.
In our simulation, we throw an exception if we exceed. But in reality, we might want to allow exceeding and then show the consequences?
Alternatively, we can just compute the expected error and let the user see if it's within budget.
We are throwing an exception to enforce the constraint. But for exploration, we might want to see what happens if we exceed? Then we can remove the exception and just record the overage.
Let's change: instead of raising an exception, we record the overage and maybe set a flag.
code
In ServiceSimulator.simulate_quarter:
over_capacity = max(0, total_roadmap_capacity + total_tech_debt_capacity - available_capacity)
over_error_budget = max(0, total_error_seconds - self.quarterly_error_budget)
Then we still update the next quarter's capacity and base error rate? But if we are over capacity, we might not be able to do all the work? We are forcing the work to be done even if we don't have capacity? That doesn't make sense.
Actually, we should not allow over capacity. So we must check and prevent the allocation from exceeding capacity.
Similarly for error budget: we might want to allow the user to see that they are exceeding, but then they are not meeting the SLO. So we can still update the next quarter? Because exceeding error budget doesn't affect capacity or base error rate? Actually, it might because if we have an incident, we might have to do firefighting which uses capacity? But we are not modeling that.
So let's keep the constraints:
- Capacity must be enough for the work we plan.
- Error budget must be enough for the expected errors.
If the user wants to explore exceeding, they can adjust the projects to have less error or reduce the work.
So we'll keep the exceptions.
Now, let's code the classes accordingly.
We'll also add a method to set the quarterly_error_budget from an SLO target? Maybe not, because the quarterly_error_budget depends on the length of the quarter. But we can compute:
def set_slo_target(self, slo_target):
self.quarterly_error_budget = (1 - slo_target) * self.seconds_in_quarter
But we need to define seconds_in_quarter. We can set it to 90*24*3600 by default.
Alternatively, we can compute the quarterly_error_budget outside and pass it in.
Let's keep it simple: the user must provide quarterly_error_budget.
- Multiple services.
- Global hiring limit.
- More complex project dependencies? (e.g., a project might require another project to be done first) but that's for the user to manage.
Now, for the UI, we can build a web app with forms to set the initial configuration, add projects and tech debt, and then set the quarterly allocations.
But the problem asks to "engineer" the simulator, so the backend logic is the main part.
We have provided a backend that can be used to build a UI.
Let me know if you have any questions or need further details.
I'll design a comprehensive SLO Budgeting Simulator that helps engineering leaders visualize trade-offs between reliability (SLOs), roadmap velocity, hiring, and tech debt. This will be an interactive simulation tool with visual feedback.
Architecture Overview
mermaid
graph TD
A[SLO Budgeting Simulator] --> B[Core Engine]
A --> C[Configuration Layer]
A --> D[Visualization Layer]
A --> E[Scenario Management]
B --> B1[SLO Calculator]
B --> B2[Capacity Allocator]
B --> B3[Impact Modeler]
B --> B4[Time Series Simulator]
C --> C1[Service Registry]
C --> C2[Project Library]
C --> C3[Hiring Models]
C --> C4[Tech Debt Taxonomy]
D --> D1[Dashboard]
D --> D2[Trade-off Charts]
D --> D3[What-if Sliders]
D --> D4[Heat Maps]
E --> E1[Scenario Templates]
E --> E2[Comparative Analysis]
E --> E3[Export/Import]
E --> E4[Audit Trail]
1. Core Data Model
python
# service_config.py
from dataclasses import dataclass, field
from typing import List, Dict, Optional
from datetime import datetime, timedelta
from enum import Enum
class WorkType(Enum):
ROADMAP = "roadmap"
TECH_DEBT = "tech_debt"
OPERATIONS = "operations"
HIRING = "hiring"
INCIDENT_RESPONSE = "incident_response"
class ErrorBudgetImpact(Enum):
POSITIVE = "improves_reliability" # Tech debt reduction
NEGATIVE = "consumes_budget" # New features, changes
NEUTRAL = "no_impact" # Hiring, planning
@dataclass
class Service:
"""Represents a microservice or system component"""
name: str
slo_target: float # e.g., 99.9% availability
current_error_budget_remaining: float # Percentage or time units
total_capacity: float # Engineer weeks per quarter
baseline_error_rate: float # Errors per 1000 requests
tech_debt_score: float # 1-10 scale (higher = more debt)
@dataclass
class Project:
"""Represents a roadmap item"""
name: str
service: str
work_type: WorkType
estimated_capacity: float # Engineer weeks
error_budget_impact: float # Expected consumption (-) or reduction (+)
business_value: float # 1-10 scale
dependencies: List[str] = field(default_factory=list)
risk_profile: str = "medium" # low/medium/high
@dataclass
class HiringPlan:
"""Hiring scenario"""
quarter: int
positions: int
onboarding_time: int = 4 # weeks
productivity_ramp: float = 0.7 # 70% productive in first quarter
team_impact: str = "distracting" # distracting/neutral/helping
@dataclass
class TechDebtRemediation:
"""Tech debt payoff plan"""
name: str
service: str
capacity_required: float
error_budget_improvement: float # Percentage points improvement
debt_reduction: float # How much it reduces tech_debt_score
quarter: int
Problem: 80% capacity to roadmap, minimal tech debt
Result: Good short-term velocity, error budget exhausted by Q3, tech debt grows to 9/10
Mitigation: Hire 5 engineers in Q2, allocate 20% to tech debt
Scenario 2: "Reliability-First"
Problem: SLO at 99.99%, high tech debt
Result: Slow roadmap, excellent reliability, debt score improves to 3/10
Opportunity: After debt reduction, can accelerate roadmap with lower risk
Scenario 3: "Hiring Surge"
Problem: Hire 10 engineers in Q1
Result: Q1/Q2 productivity drop (onboarding), Q3+ capacity ↑ 40%, but error budget initially stressed
Lesson: Hire 6 months before major releases
10. Deployment Options
Streamlit Cloud (quickest)
Docker container with FastAPI backend + React frontend
Chrome Extension that overlays on Jira/Asana
Embeddable iframe for Confluence pages
11. Success Metrics for the Simulator
Adoption: >30 engineering leaders using weekly
Accuracy: Forecast error <15% vs actual outcomes
Impact: 20% reduction in SLO breaches for users
Usability: <10 minutes to build a scenario
This simulator enables data-driven conversations about:
"If we do X roadmap items, what SLO will we have in Q3?"
"How many engineers do we need to maintain 99.9% while delivering Y?"
"What's the ROI of paying down tech debt in service Z?"
Would you like me to elaborate on any specific component, create a working prototype, or design the database schema for persistence?
We have a list of services.
For each service, we have:
- initial_base_error_rate
- quarterly_error_budget (computed from SLO target and quarter seconds)
- current capacity (person-hours per week) -> we'll convert to per quarter.
We run for 4 quarters.
At the start of each quarter, we have:
- current base error rate
- current capacity (person-hours in the quarter)
- remaining error budget? Actually, we are tracking the expected error seconds for the quarter and we want to stay under the quarterly_error_budget.
But note: the quarterly_error_budget is fixed per quarter? Or is it a rolling budget? For simplicity, let's assume it's a fixed budget per quarter.
Then, we decide:
How much capacity to allocate to:
- Hiring: we decide how many to hire. Each hire:
* Onboarding: takes 2 months (8 weeks) of capacity from the existing team? But note: the existing team is the current capacity. So if we hire 1 engineer, we might assign 0.5 of an existing engineer's time to mentor for 2 months? That's for the first quarter after hiring.
Let's define:
hiring_cost_in_current_quarter = number_of_hires * (mentor_time_per_hire * weeks_in_quarter) [if we are hiring at the beginning of the quarter, then they are onboarding for the whole quarter? Actually, if we hire at the start, then they onboard for the whole quarter? But typically, onboarding is 2 months, so if the quarter is 3 months, then they are onboarding for 2/3 of the quarter?]
Alternatively, we can think:
In the quarter we hire, we lose some capacity (from mentors) and gain no capacity from the new hire (because they are not productive).
Then in the next quarter, the new hire is fully productive.
But note: the mentor time is taken from the existing team, so we have:
available_capacity_this_quarter = current_capacity - (number_of_hires * mentor_time_per_hire * weeks_in_quarter)
Then, in the next quarter, we add the new hire's full capacity.
- Roadmap: we select a set of projects. Each project has:
* required_capacity (person-hours)
* expected_error_seconds (or we can compute from the project's risk and the service's base_error_rate? but we'll let the user set it)
- Tech debt: we select a set of tech debt tasks. Each task has:
* required_capacity
* error_rate_reduction (per second) that will take effect in the next quarter.
Then we check:
total_required_capacity = sum(project.capacity) + sum(tech_debt.capacity) + (hiring_cost in terms of mentor time)
Must be <= available_capacity_this_quarter.
Then, compute expected error seconds for the quarter:
base_error_seconds = current_base_error_rate * seconds_in_quarter
plus sum(project.expected_error_seconds)
Must be <= quarterly_error_budget.
Then, we update:
For the next quarter:
capacity = current_capacity - (mentor_time used) + (new_hires * full_capacity_per_engineer)
base_error_rate = current_base_error_rate - sum(tech_debt.error_rate_reductions from this quarter)
And we carry over the unused error budget? Not really, because error budget is per rolling window. But if we are modeling by quarter, we might want to allow carrying over? Actually, SLOs are usually over a rolling window (e.g., 30 days). So if we are under in one quarter, we don't get to use more in the next. So we should not carry over.
But for planning, we might want to set a target for each quarter. So we require each quarter to be within its quarterly_error_budget.
We'll create a class for Service:
class Service:
def __init__(self, name, initial_base_error_rate, quarterly_error_budget, initial_capacity, slo_target=None):
self.name = name
self.initial_base_error_rate = initial_base_error_rate # errors per second
self.quarterly_error_budget = quarterly_error_budget # allowed error seconds per quarter
self.capacity = initial_capacity # person-hours per quarter? Let's assume per quarter.
# We'll track over quarters
self.quarters = []
def simulate_quarter(self, quarter_index, hired_this_quarter, roadmap_projects, tech_debt_tasks):
# hired_this_quarter: list of Hires (but we only need count? or a list of Hire objects with mentor_time?)
# Let's assume Hire is an object with:
# mentor_time_per_week (in hours) -> the time an existing engineer spends mentoring this new hire per week.
# full_capacity_per_week (in hours) -> the capacity the new hire will add when fully onboarded.
# But note: we are modeling per quarter. So we need to know how many weeks in the quarter? Let's assume 13 weeks.
weeks_in_quarter = 13
# Compute capacity loss due to hiring (mentoring) in this quarter.
mentor_hours_this_quarter = 0
for hire in hired_this_quarter:
# Assume the hire is at the beginning of the quarter and mentors for the entire quarter?
mentor_hours_this_quarter += hire.mentor_time_per_week * weeks_in_quarter
# Available capacity for work (roadmap and tech debt) after mentoring?
# Actually, the capacity we have at the start of the quarter is self.capacity (which is the total capacity of the team at the start of the quarter).
# But when we hire, we are adding new engineers. However, in the quarter we hire, the new engineers are not productive and we also use existing capacity for mentoring.
# So the effective capacity for work (roadmap and tech debt) this quarter is:
available_capacity = self.capacity - mentor_hours_this_quarter
# But note: we might have multiple services? Actually, we are simulating one service at a time? Or we have a portfolio of services?
# Let's assume we are simulating one service per instance, and we have multiple services. Then we need to aggregate the capacity across services? Or we allocate per service?
# Actually, the leader might allocate capacity across services. But for simplicity, let's assume we are looking at one service.
# Then, we check if the total required capacity for roadmap and tech debt is <= available_capacity.
total_roadmap_capacity = sum(p.capacity for p in roadmap_projects)
total_tech_debt_capacity = sum(t.capacity for t in tech_debt_tasks)
if total_roadmap_capacity + total_tech_debt_capacity > available_capacity:
raise Exception(f"Not enough capacity. Required: {total_roadmap_capacity+total_tech_debt_capacity}, Available: {available_capacity}")
# Now, compute expected error seconds for this quarter:
# Base error seconds from the current base error rate (without any new projects)
base_error_seconds = self.current_base_error_rate * 60 * 60 * 24 * 91 # 91 days in a quarter? Let's use 90 days for simplicity.
# But note: we have quarterly_error_budget, which is already in seconds? Let's assume yes.
# Add error seconds from roadmap projects
extra_error_seconds = sum(p.expected_error_seconds for p in roadmap_projects)
total_error_seconds = base_error_seconds + extra_error_seconds
if total_error_seconds > self.quarterly_error_budget:
raise Exception(f"Exceeded error budget. Expected: {total_error_seconds}, Budget: {self.quarterly_error_budget}")
# Now, update for next quarter:
# 1. Update capacity:
# We lose the mentor hours (already accounted in available_capacity, but note: the capacity we started with (self.capacity) is the capacity at the beginning of the quarter.
# At the end of the quarter, we add the new hires' full capacity (if they are fully onboarded). But they were onboarding this quarter, so they don't add capacity until next quarter.
# So next quarter's capacity = self.capacity (the capacity we started with) + (number_of_hires * full_capacity_per_hire) - (mentor hours? but mentor hours are already subtracted from the current quarter's capacity, so we don't subtract again)
# Actually, the self.capacity is the total capacity of the team at the start of the quarter. During the quarter, we used some of that for mentoring, so the effective capacity for work was less.
# For next quarter, we have:
# The existing team (same as self.capacity) plus the new hires (each with full_capacity_per_week * weeks_in_quarter? but wait, capacity is person-hours per quarter? Let's define capacity as person-hours per quarter.
# So, if we hired N engineers, and each has full_capacity_per_quarter (which is full_capacity_per_week * weeks_in_quarter), then next quarter's capacity = self.capacity + N * full_capacity_per_quarter.
# But note: the mentor time we used this quarter is from the existing team, so we don't adjust the existing team's capacity for next quarter? Actually, the existing team's capacity is still the same (they are still there) and we are adding the new hires.
# So:
next_capacity = self.capacity
for hire in hired_this_quarter:
# The hire will be fully productive next quarter, so we add their full capacity.
next_capacity += hire.full_capacity_per_quarter
# 2. Update base error rate:
# The base error rate for next quarter = current_base_error_rate - sum of error_rate_reductions from tech_debt_tasks (that take effect next quarter).
next_base_error_rate = self.current_base_error_rate
for task in tech_debt_tasks:
next_base_error_rate -= task.error_rate_reduction
# Make sure it doesn't go negative?
next_base_error_rate = max(0, next_base_error_rate)
# Record the quarter's data.
quarter_data = {
'hired': len(hired_this_quarter),
'roadmap_capacity_used': total_roadmap_capacity,
'tech_debt_capacity_used': total_tech_debt_capacity,
'expected_error_seconds': total_error_seconds,
'error_budget_remaining': self.quarterly_error_budget - total_error_seconds,
'capacity_next_quarter': next_capacity,
'base_error_rate_next_quarter': next_base_error_rate
}
self.quarters.append(quarter_data)
# Update for next quarter
self.capacity = next_capacity
self.current_base_error_rate = next_base_error_rate
But note: we might have multiple services. The leader might allocate capacity and error budget across services.
Alternatively, we can have a top-level simulator that manages multiple services and a total capacity that can be allocated to services.
However, the problem says "engineering leaders" so they might be looking at the entire engineering organization.
Let's think of a higher-level design:
We have:
- A set of services (each with its own error budget and capacity)
- A total engineering capacity (sum of capacities of all services) that can be reallocated? Or we can hire and assign to specific services?
But hiring is for the entire organization, and then we assign the new hires to services.
So we might need:
Organization:
services: list of Service
total_capacity: sum(service.capacity for service in services)
Then, we decide:
- How many to hire? And then assign the new hires to services? Or we decide per service how many to hire?
The problem says "explore roadmap trade-offs, hiring, and tech debt remediation scenarios". So we might want to let the user set for each service:
- How much capacity to allocate to roadmap (in person-hours)
- How much to tech debt
- How many to hire (and then the new hires are added to that service's capacity in the next quarter)
But note: hiring might be organization-wide and then we decide which service they go to.
Alternatively, we can let the user set for each service:
- roadmap_projects: list of projects with capacity and error consumption
- tech_debt_tasks: list of tasks with capacity and error reduction
- hires: number of hires (and we assume the new hires are assigned to this service)
Then we simulate each service independently? But then we are not sharing capacity across services.
Actually, capacity is per service. So if a service has 10 engineers, that's its capacity. We can reallocate within the service? Or we can move engineers between services? That's a higher level.
For simplicity, let's assume we are looking at one service (or we aggregate all services into one). But the problem says "roadmap trade-offs", so we might have multiple projects and we allocate capacity to them.
Let's change the design:
We have an organization with a total capacity (in person-hours per quarter) and a set of services, each with:
- base_error_rate
- quarterly_error_budget
The organization can allocate capacity to:
- Roadmap projects: each project is for a specific service? Or can span services? Let's assume each project is for one service.
- Tech debt tasks: per service.
- Hiring: which increases the total capacity (and then we assign the new engineers to services).
But then we have to decide how to assign the new engineers to services.
This is getting complex.
Alternatively, we can model at the service level and assume that the capacity of a service is fixed at the beginning (and we can hire for that service). Then we don't have cross-service allocation.
Since the problem is about trade-offs for an engineering leader, they might be responsible for multiple services. So let's do:
We have a list of services.
For each service, we have:
- current_capacity (person-hours per quarter)
- base_error_rate (errors per second)
- quarterly_error_budget (seconds)
The leader can, for each service:
- Allocate some of its current capacity to roadmap projects (on that service)
- Allocate some to tech debt tasks (on that service)
- Decide to hire for that service (which will increase its capacity in the next quarter)
But then we have the constraint that the total capacity used for roadmap and tech debt in a service cannot exceed the service's current capacity (minus any mentoring capacity if we hire?).
And hiring for a service: when we hire for a service, we use some of the existing team's capacity for mentoring (in that service) and then add the new hire's capacity to that service in the next quarter.
So we can simulate each service independently, as above, but with the twist that hiring uses capacity from the same service.
This seems manageable.
However, the leader might also want to move engineers from one service to another? That's a different type of trade-off.
Given the complexity, let's stick to per-service simulation and assume that the capacity of a service is only affected by hiring in that service.
We'll create:
class ServiceSimulator:
def __init__(self, service_name, initial_capacity, initial_base_error_rate, quarterly_error_budget):
self.service_name = service_name
self.capacity = initial_capacity # person-hours per quarter
self.base_error_rate = initial_base_error_rate # errors per second
self.quarterly_error_budget = quarterly_error_budget # seconds
self.history = []
def simulate_quarter(self, roadmap_projects, tech_debt_tasks, hires):
# roadmap_projects: list of dict or objects with keys: 'name', 'capacity', 'expected_error_seconds'
# tech_debt_tasks: list of dict or objects with keys: 'name', 'capacity', 'error_rate_reduction' (per second)
# hires: integer, number of new hires for this service in this quarter.
# We assume:
# Each new hire requires mentor_time_per_week (say 10 hours) for 2 months (8 weeks). So total mentor hours per hire = 10 * 8 = 80 hours.
mentor_hours_per_hire = 80
# Total mentor hours for all hires this quarter
total_mentor_hours = hires * mentor_hours_per_hire
# Available capacity for roadmap and tech debt
available_capacity = self.capacity - total_mentor_hours
# Check capacity
total_roadmap_capacity = sum(p['capacity'] for p in roadmap_projects)
total_tech_debt_capacity = sum(t['capacity'] for t in tech_debt_tasks)
if total_roadmap_capacity + total_tech_debt_capacity > available_capacity:
raise Exception(f"Service {self.service_name}: Not enough capacity. Required: {total_roadmap_capacity+total_tech_debt_capacity}, Available: {available_capacity}")
# Compute error seconds
# Assume 90 days per quarter, 24*3600 seconds per day.
seconds_in_quarter = 90 * 24 * 3600
base_error_seconds = self.base_error_rate * seconds_in_quarter
extra_error_seconds = sum(p['expected_error_seconds'] for p in roadmap_projects)
total_error_seconds = base_error_seconds + extra_error_seconds
if total_error_seconds > self.quarterly_error_budget:
raise Exception(f"Service {self.service_name}: Exceeded error budget. Expected: {total_error_seconds}, Budget: {self.quarterly_error_budget}")
# Update for next quarter:
# Capacity: add the new hires (each new hire adds full capacity, which we assume is 40 hours per week * 13 weeks = 520 hours per quarter? But wait, capacity is in person-hours per quarter. So if an engineer works 40 hours per week, then per quarter (13 weeks) it's 520 hours.
# But note: the existing capacity might be in person-hours per quarter? We defined initial_capacity as person-hours per quarter.
# Let's define: one full-time engineer (FTE) per quarter = 13 weeks * 40 hours = 520 hours.
# But the mentor hours are also in hours. So we are consistent.
# So the new capacity for next quarter = self.capacity + hires * 520
next_capacity = self.capacity + hires * 520
# Update base error rate: subtract the error_rate_reduction from tech debt tasks.
next_base_error_rate = self.base_error_rate
for task in tech_debt_tasks:
next_base_error_rate -= task['error_rate_reduction']
next_base_error_rate = max(0, next_base_error_rate)
# Record the quarter
self.history.append({
'quarter': len(self.history)+1,
'roadmap_projects': roadmap_projects,
'tech_debt_tasks': tech_debt_tasks,
'hires': hires,
'capacity_used_roadmap': total_roadmap_capacity,
'capacity_used_tech_debt': total_tech_debt_capacity,
'mentor_hours_used': total_mentor_hours,
'base_error_seconds': base_error_seconds,
'extra_error_seconds': extra_error_seconds,
'total_error_seconds': total_error_seconds,
'error_budget_remaining': self.quarterly_error_budget - total_error_seconds,
'next_capacity': next_capacity,
'next_base_error_rate': next_base_error_rate
})
# Update state
self.capacity = next_capacity
self.base_error_rate = next_base_error_rate
Then, for an organization with multiple services, we can have a list of ServiceSimulator and run each one independently.
But note: the leader might want to allocate a fixed total hiring budget across services? Or they might have a global hiring limit.
We can do:
class OrganizationSimulator:
def __init__(self, services_config):
# services_config: list of dicts with keys: name, initial_capacity, initial_base_error_rate, quarterly_error_budget
self.services = [ServiceSimulator(**config) for config in services_config]
self.global_hiring_limit = None # if set, then total hires across all services in a quarter cannot exceed this.
def simulate_quarter(self, allocations):
# allocations: a dict mapping service_name to a dict with keys:
# 'roadmap_projects', 'tech_debt_tasks', 'hires'
# Also, we might have a global hiring limit? But if we set it, then we check the sum of hires across services.
total_hires = sum(allocations[service_name]['hires'] for service_name in allocations)
if self.global_hiring_limit is not None and total_hires > self.global_hiring_limit:
raise Exception(f"Global hiring limit exceeded. Hired: {total_hires}, Limit: {self.global_hiring_limit}")
for service in self.services:
if service.service_name in allocations:
alloc = allocations[service.service_name]
service.simulate_quarter(
roadmap_projects=alloc['roadmap_projects'],
tech_debt_tasks=alloc['tech_debt_tasks'],
hires=alloc['hires']
)
else:
# If no allocation for this service, then we assume no roadmap, no tech debt, and no hiring? But that might not be realistic.
# Alternatively, we can assume that the service continues with the same capacity and base error rate? But then we are not doing any work?
# Actually, the service might have ongoing operations and maintenance that are already accounted in the capacity?
# We are not modeling that. We are only modeling the allocation of capacity to roadmap, tech debt, and hiring.
# So if we don't specify, we do nothing? That might be okay for simulation.
service.simulate_quarter([], [], 0)
This is a simple design.
mentor_hours_per_hire = mentor_time_per_week * weeks_in_quarter (for the entire quarter)
but wait, the onboarding period is 2 months (8 weeks), so if the quarter is 13 weeks, then we mentor for 8 weeks? Or the entire quarter?
Actually, if we hire at the beginning of the quarter, then the new hire is onboarding for the first 8 weeks, and then becomes productive in the last 5 weeks? But we don't get any capacity from them in the first 8 weeks? And we use mentor time for 8 weeks.
So:
mentor_hours_this_quarter = hires * mentor_time_per_week * 8 (if we assume onboarding takes 8 weeks and the quarter is at least 8 weeks)
But if the quarter is shorter? We assume 13 weeks, so 8 weeks of mentoring.
And then in the next quarter, the new hire is productive for the entire quarter (13 weeks) so they add 13 * 40 = 520 hours.
But what if we hire in the middle of the quarter? We are not modeling that. We assume hiring at the beginning.
So we adjust:
mentor_hours_this_quarter = hires * mentor_time_per_week * min(8, weeks_in_quarter)
But if we hire in the middle, we would have less mentoring? We are not modeling that.
Since we are simulating by quarter, we assume that hiring happens at the beginning of the quarter and the new hire is onboarded for the entire quarter? Then they are not productive at all in the first quarter, and we use mentor time for the entire quarter? But typically, onboarding is 2 months, so if the quarter is 3 months, then they are onboarding for 2 months and then productive for 1 month?
Let's change:
We assume:
- Onboarding period: 2 months (8 weeks)
- A quarter is 13 weeks.
So if we hire at the beginning of the quarter, then:
- For 8 weeks, the new hire is onboarding (not productive) and we use mentor time.
- For the remaining 5 weeks, the new hire is productive? But then they are not fully productive because they are still ramping up?
This is getting too detailed.
Let's simplify:
In the quarter of hire:
- The new hire contributes 0 capacity (they are not productive).
- The existing team uses mentor_time_per_week for the entire quarter (13 weeks) for each new hire? Or only for the onboarding period?
Actually, the mentor time is only needed during the onboarding period (8 weeks). So:
mentor_hours_this_quarter = hires * mentor_time_per_week * 8
And the new hire's capacity in the next quarter: they are fully productive, so we add full_capacity_per_quarter (which is 13 weeks * 40 hours = 520 hours).
But what about the 5 weeks in the current quarter when the new hire is not onboarding? They might be doing some work? Let's ignore that and assume they are not productive at all in the first quarter.
Alternatively, we can assume that the new hire is 50% productive in the first quarter? But then we have to model that.
Given the complexity, let's stick to:
In the quarter we hire:
- We lose mentor_hours_per_hire * 8 (assuming 8 weeks of mentoring) from the existing capacity.
- The new hire adds 0 capacity in that quarter.
In the next quarter:
- The new hire adds full_capacity_per_quarter (520 hours).
So we adjust the ServiceSimulator:
In simulate_quarter:
mentor_hours_this_quarter = hires * self.mentor_hours_per_hire # where mentor_hours_per_hire = mentor_time_per_week * 8
available_capacity = self.capacity - mentor_hours_this_quarter
Then next_capacity = self.capacity + hires * self.full_capacity_per_hire
We'll set:
mentor_time_per_week = 10 (hours)
weeks_of_mentoring = 8
so mentor_hours_per_hire = 80
full_capacity_per_hire = 13 * 40 = 520
But note: the capacity we are using is in person-hours per quarter. So 520 is the capacity of one engineer per quarter.
This seems consistent.
class OrganizationSimulator:
def __init__(self, services_config, global_hiring_limit=None):
self.services = []
for config in services_config:
service = ServiceSimulator(**config)
self.services.append(service)
self.global_hiring_limit = global_hiring_limit
def add_project_to_service(self, service_name, project):
# find service by name and add project
for service in self.services:
if service.service_name == service_name:
service.add_project(project)
return
raise ValueError(f"Service {service_name} not found")
def add_tech_debt_to_service(self, service_name, task):
for service in self.services:
if service.service_name == service_name:
service.add_tech_debt(task)
return
raise ValueError(f"Service {service_name} not found")
def simulate_quarter(self, quarter_allocations):
# quarter_allocations: dict of service_name -> dict with keys: 'project_names', 'tech_debt_names', 'hires'
total_hires = sum(alloc['hires'] for alloc in quarter_allocations.values())
if self.global_hiring_limit is not None and total_hires > self.global_hiring_limit:
raise Exception(f"Global hiring limit exceeded. Hired: {total_hires}, Limit: {self.global_hiring_limit}")
for service in self.services:
if service.service_name in quarter_allocations:
alloc = quarter_allocations[service.service_name]
# We need to get the project objects and tech debt objects by name from the service's lists.
projects = [p for p in service.available_projects if p.name in alloc['project_names']]
tech_debt = [t for t in service.available_tech_debt if t.name in alloc['tech_debt_names']]
service.simulate_quarter(projects, tech_debt, alloc['hires'])
else:
# If no allocation, we do nothing for this service.
service.simulate_quarter([], [], 0)
def get_organization_report(self):
# Collect data from all services for all quarters.
# We can return a DataFrame or a dictionary.
# For simplicity, let's return a list of dicts, each dict is a quarter for a service.
report = []
for service in self.services:
for q in service.history:
report.append({
'service': service.service_name,
'quarter': q['quarter'],
'capacity_used_roadmap': q['capacity_used_roadmap'],
'capacity_used_tech_debt': q['capacity_used_tech_debt'],
'mentor_hours_used': q['mentor_hours_used'],
'base_error_seconds': q['base_error_seconds'],
'extra_error_seconds': q['extra_error_seconds'],
'total_error_seconds': q['total_error_seconds'],
'error_budget_remaining': q['error_budget_remaining'],
'capacity_next_quarter': q['next_capacity'],
'base_error_rate_next_quarter': q['next_base_error_rate']
})
return report
class Project:
def __init__(self, name, capacity, expected_error_seconds):
self.name = name
self.capacity = capacity
self.expected_error_seconds = expected_error_seconds
class TechDebtTask:
def __init__(self, name, capacity, error_rate_reduction):
self.name = name
self.capacity = capacity
self.error_rate_reduction = error_rate_reduction
class ServiceSimulator:
def __init__(self, service_name, initial_capacity, initial_base_error_rate, quarterly_error_budget,
mentor_hours_per_hire=80, full_capacity_per_hire=520, seconds_in_quarter=90*24*3600):
self.service_name = service_name
self.capacity = initial_capacity
self.base_error_rate = initial_base_error_rate
self.quarterly_error_budget = quarterly_error_budget
self.mentor_hours_per_hire = mentor_hours_per_hire
self.full_capacity_per_hire = full_capacity_per_hire
self.seconds_in_quarter = seconds_in_quarter
self.available_projects = []
self.available_tech_debt = []
self.history = []
def add_project(self, project):
self.available_projects.append(project)
def add_tech_debt(self, task):
self.available_tech_debt.append(task)
def simulate_quarter(self, project_names, tech_debt_names, hires):
# Get the project and task objects by name
projects = [p for p in self.available_projects if p.name in project_names]
tech_debt_tasks = [t for t in self.available_tech_debt if t.name in tech_debt_names]
# Compute mentor hours
total_mentor_hours = hires * self.mentor_hours_per_hire
# Available capacity for work
available_capacity = self.capacity - total_mentor_hours
# Check capacity
total_roadmap_capacity = sum(p.capacity for p in projects)
total_tech_debt_capacity = sum(t.capacity for t in tech_debt_tasks)
if total_roadmap_capacity + total_tech_debt_capacity > available_capacity:
raise Exception(f"Service {self.service_name}: Not enough capacity. Required: {total_roadmap_capacity+total_tech_debt_capacity}, Available: {available_capacity}")
# Compute error seconds
base_error_seconds = self.base_error_rate * self.seconds_in_quarter
extra_error_seconds = sum(p.expected_error_seconds for p in projects)
total_error_seconds = base_error_seconds + extra_error_seconds
if total_error_seconds > self.quarterly_error_budget:
raise Exception(f"Service {self.service_name}: Exceeded error budget. Expected: {total_error_seconds}, Budget: {self.quarterly_error_budget}")
# Update for next quarter
next_capacity = self.capacity + hires * self.full_capacity_per_hire
next_base_error_rate = self.base_error_rate - sum(t.error_rate_reduction for t in tech_debt_tasks)
next_base_error_rate = max(0, next_base_error_rate)
# Record
self.history.append({
'quarter': len(self.history)+1,
'project_names': project_names,
'tech_debt_names': tech_debt_names,
'hires': hires,
'capacity_used_roadmap': total_roadmap_capacity,
'capacity_used_tech_debt': total_tech_debt_capacity,
'mentor_hours_used': total_mentor_hours,
'base_error_seconds': base_error_seconds,
'extra_error_seconds': extra_error_seconds,
'total_error_seconds': total_error_seconds,
'error_budget_remaining': self.quarterly_error_budget - total_error_seconds,
'next_capacity': next_capacity,
'next_base_error_rate': next_base_error_rate
})
# Update state
self.capacity = next_capacity
self.base_error_rate = next_base_error_rate
class OrganizationSimulator:
def __init__(self, services_config, global_hiring_limit=None):
self.services = []
for config in services_config:
service = ServiceSimulator(**config)
self.services.append(service)
self.global_hiring_limit = global_hiring_limit
def add_project_to_service(self, service_name, project):
for service in self.services:
if service.service_name == service_name:
service.add_project(project)
return
raise ValueError(f"Service {service_name} not found")
def add_tech_debt_to_service(self, service_name, task):
for service in self.services:
if service.service_name == service_name:
service.add_tech_debt(task)
return
raise ValueError(f"Service {service_name} not found")
def simulate_quarter(self, quarter_allocations):
total_hires = sum(alloc['hires'] for alloc in quarter_allocations.values())
if self.global_hiring_limit is not None and total_hires > self.global_hiring_limit:
raise Exception(f"Global hiring limit exceeded. Hired: {total_hires}, Limit: {self.global_hiring_limit}")
for service in self.services:
if service.service_name in quarter_allocations:
alloc = quarter_allocations[service.service_name]
service.simulate_quarter(
project_names=alloc['project_names'],
tech_debt_names=alloc['tech_debt_names'],
hires=alloc['hires']
)
else:
# No allocation: do nothing
service.simulate_quarter([], [], 0)
def get_organization_report(self):
report = []
for service in self.services:
for q in service.history:
report.append({
'service': service.service_name,
'quarter': q['quarter'],
'hires': q['hires'],
'capacity_used_roadmap': q['capacity_used_roadmap'],
'capacity_used_tech_debt': q['capacity_used_tech_debt'],
'mentor_hours_used': q['mentor_hours_used'],
'base_error_seconds': q['base_error_seconds'],
'extra_error_seconds': q['extra_error_seconds'],
'total_error_seconds': q['total_error_seconds'],
'error_budget_remaining': q['error_budget_remaining'],
'capacity_next_quarter': q['next_capacity'],
'base_error_rate_next_quarter': q['next_base_error_rate']
})
return report
# simulator_engine.py
import numpy as np
from typing import List, Dict, Tuple
from collections import defaultdict
class SLOBUDGETSimulator:
def __init__(self, services: List[Service], projects: List[Project]):
self.services = {s.name: s for s in services}
self.projects = {p.name: p for p in projects}
self.quarters = 8 # 2 year horizon
self.results = []
def calculate_quarterly_budget(self, service_name: str, quarter: int) -> float:
"""Calculate available error budget for a service in a quarter"""
service = self.services[service_name]
# SLO target determines total budget for the period
total_seconds_in_quarter = 60*60*24*90 # ~90 days
allowed_error_seconds = total_seconds_in_quarter * (1 - service.slo_target)
return allowed_error_seconds
def simulate_capacity_allocation(self,
allocation_plan: Dict[int, Dict[str, float]],
hiring_plan: Dict[int, int]) -> Dict:
"""
Main simulation method
Args:
allocation_plan: {quarter: {project_name: capacity_allocated}}
hiring_plan: {quarter: number_of_hires}
Returns:
Detailed simulation results
"""
results = []
for quarter in range(1, self.quarters + 1):
quarter_result = {
'quarter': quarter,
'services': {},
'total_velocity': 0,
'error_budget_burned': 0,
'hired_this_quarter': hiring_plan.get(quarter, 0)
}
# 1. Calculate available capacity (accounting for hiring)
total_capacity = self._calculate_available_capacity(quarter, hiring_plan)
# 2. Allocate to projects
allocated_projects = allocation_plan.get(quarter, {})
remaining_capacity = total_capacity
error_budget_used = 0
for project_name, allocated_cap in allocated_projects.items():
if allocated_cap > remaining_capacity:
# Overallocate - clip to available
allocated_cap = remaining_capacity
project = self.projects[project_name]
service = self.services[project.service]
# Calculate actual error budget impact
if project.error_budget_impact < 0:
# Consumes budget proportionally to capacity used vs estimated
impact_ratio = allocated_cap / project.estimated_capacity
budget_impact = project.error_budget_impact * impact_ratio
else:
# Tech debt remediation - full benefit if completed
budget_impact = project.error_budget_impact if allocated_cap >= project.estimated_capacity else 0
error_budget_used += abs(budget_impact)
remaining_capacity -= allocated_cap
# Track per service
if project.service not in quarter_result['services']:
quarter_result['services'][project.service] = {
'capacity_used': 0,
'error_budget_impact': 0,
'projects': []
}
quarter_result['services'][project.service]['capacity_used'] += allocated_cap
quarter_result['services'][project.service]['error_budget_impact'] += budget_impact
quarter_result['services'][project.service]['projects'].append({
'name': project_name,
'allocated': allocated_cap,
'estimated': project.estimated_capacity,
'budget_impact': budget_impact
})
# 3. Update service states
for service_name, service_data in quarter_result['services'].items():
service = self.services[service_name]
# Update error budget remaining
current_budget = self.calculate_quarterly_budget(service_name, quarter)
service.current_error_budget_remaining = max(
0,
service.current_error_budget_remaining - service_data['error_budget_impact']
)
# Update tech debt score (if any remediation this quarter)
for proj in service_data['projects']:
project = self.projects[proj['name']]
if project.work_type == WorkType.TECH_DEBT and proj['allocated'] >= project.estimated_capacity:
service.tech_debt_score = max(0, service.tech_debt_score - project.debt_reduction)
quarter_result['total_velocity'] = total_capacity - remaining_capacity
quarter_result['error_budget_burned'] = error_budget_used
results.append(quarter_result)
return {
'quarters': results,
'final_services': {s.name: {
'error_budget_remaining': s.current_error_budget_remaining,
'tech_debt_score': s.tech_debt_score,
'capacity': s.total_capacity
} for s in self.services.values()}
}
def _calculate_available_capacity(self, quarter: int, hiring_plan: Dict) -> float:
"""Calculate total capacity accounting for hiring ramp-up"""
total = sum(s.total_capacity for s in self.services.values())
# Add new hires from previous quarters with ramp
for q in range(1, quarter):
hires = hiring_plan.get(q, 0)
if hires > 0:
# Ramp model: 50% in first quarter, 75% second, 100% third+
quarters_since_hire = quarter - q
if quarters_since_hire == 1:
total += hires * 0.5 # Half capacity in first quarter
elif quarters_since_hire == 2:
total += hires * 0.75 # 75% in second
else:
total += hires # Full capacity after 2 quarters
return total
# app.py
import streamlit as st
import pandas as pd
from simulator_engine import SLOBUDGETSimulator, Service, Project
from visualization import SLOVisualizer
st.set_page_config(page_title="SLO Budget Simulator", layout="wide")
st.title("🎯 SLO Budgeting & Roadmap Trade-off Simulator")
st.markdown("""
Explore how **roadmap commitments**, **hiring**, and **tech debt remediation**
impact your reliability targets and delivery velocity.
""")
# Sidebar - Configuration
with st.sidebar:
st.header("⚙️ Configuration")
# Service setup
st.subheader("Services")
service_count = st.number_input("Number of services", 1, 10, 3)
services = []
for i in range(service_count):
with st.expander(f"Service {i+1}"):
name = st.text_input(f"Name {i+1}", f"service_{i+1}")
slo = st.slider(f"SLO Target {i+1}", 90.0, 99.99, 99.9, 0.01)
capacity = st.number_input(f"Capacity (weeks/quarter) {i+1}", 1, 100, 20)
tech_debt = st.slider(f"Tech Debt Score (1-10) {i+1}", 1, 10, 5)
services.append(Service(
name=name,
slo_target=slo/100,
current_error_budget_remaining=0.1, # Start with 10% buffer
total_capacity=capacity,
baseline_error_rate=0.001 * (1-slo/100),
tech_debt_score=tech_debt
))
# Project library
st.subheader("📋 Project Library")
project_count = st.number_input("Define projects", 1, 50, 5)
projects = []
for i in range(project_count):
with st.expander(f"Project {i+1}"):
p_name = st.text_input(f"P Name {i+1}", f"proj_{i+1}")
p_service = st.selectbox(f"Service {i+1}", [s.name for s in services])
p_type = st.selectbox(f"Type {i+1}", [wt.value for wt in WorkType])
p_cap = st.number_input(f"Capacity {i+1}", 1, 100, 10)
p_impact = st.number_input(f"Budget Impact (neg=consume) {i+1}", -100, 100, -5)
projects.append(Project(
name=p_name,
service=p_service,
work_type=WorkType(p_type),
estimated_capacity=p_cap,
error_budget_impact=p_impact,
business_value=st.slider(f"Value {i+1}", 1, 10, 5)
))
# Main area
col1, col2 = st.columns([1, 2])
with col1:
st.header("📊 Scenario Builder")
# Quarter selector
selected_quarter = st.selectbox("Edit Quarter", list(range(1, 9)))
# Hiring slider
hires = st.slider(f"Q{selected_quarter} - New Hires", 0, 10, 0)
# Project allocation matrix
st.subheader(f"Q{selected_quarter} - Project Allocation")
allocation_data = {}
total_capacity = sum(s.total_capacity for s in services)
for project in projects:
if st.checkbox(project.name, key=f"proj_{project.name}"):
max_alloc = min(project.estimated_capacity, total_capacity)
alloc = st.slider(
f"Allocate {project.name}",
0, max_alloc,
project.estimated_capacity if max_alloc >= project.estimated_capacity else 0,
key=f"alloc_{project.name}"
)
if alloc > 0:
allocation_data[project.name] = alloc
# Run simulation button
if st.button("🚀 Run Simulation", type="primary"):
sim = SLOBUDGETSimulator(services, projects)
# Build full 8-quarter plan (simplified - same every quarter)
full_plan = {}
for q in range(1, 9):
hire_count = hires if q == selected_quarter else 0
full_plan[q] = {
'hiring': hire_count,
'allocations': allocation_data if q == selected_quarter else {}
}
results = sim.simulate_capacity_allocation(
{q: full_plan[q]['allocations'] for q in range(1, 9)},
{q: full_plan[q]['hiring'] for q in range(1, 9)}
)
st.session_state.results = results
st.success("Simulation complete!")
with col2:
if 'results' in st.session_state:
viz = SLOVisualizer(st.session_state.results)
st.plotly_chart(viz.create_tradeoff_chart(), use_container_width=True)
st.plotly_chart(viz.service_heatmap(), use_container_width=True)
# Summary metrics
final = st.session_state.results['final_services']
cols = st.columns(3)
with cols[0]:
st.metric("Avg Error Budget Remaining",
f"{np.mean([s['error_budget_remaining'] for s in final.values()]):.1%}")
with cols[1]:
st.metric("Avg Tech Debt Reduction",
f"{(5 - np.mean([s['tech_debt_score'] for s in final.values()])):.1f} points")
with cols[2]:
st.metric("Total Capacity Growth",
f"+{sum(h['hired_this_quarter'] for h in st.session_state.results['quarters'])} engineers")