Bottlenecks and trade-offs
How do we find the cause of a bottleneck?
We investigate slow search, contention for a vehicle and backlog at the worker. The diagnosis combines measurement, cause, measure and accepted disadvantage. These are test assumptions; measurements on an implementation are still pending.
Starting point From Step 7: API and Worker process R-17 separately; local states, external response and compensation are traceable.
Assumptions for the example case
Example design: an operator, specifically assigned vehicles, planned periods and a region. Figures are illustrative design assumptions, not company data.
Select three diagnostic pathways
The vehicle search takes too long and misses the p95 target of one second.
- 01SymptomSearch for over 1 s
The p95 target for vehicle search missed.
- 02Measurementp95, Query, SQL
Measure 46 searches/s, time-range query duration and SQL utilization.
- 03Measurement hypothesisQuery or DB slow
Check missing index, expensive query or overload.
- 04ActionAdjust search and index
Optimize SQL search and re-check the measurement result.
- 05DisadvantageMore storage, more write work
An index speeds up searches and burdens write changes.
Each extension depends on a measurement. The start design remains in place until the associated bottleneck is proven.
Examine three situations in the case of rental
Further reading
| Possible situation | What we measure | What cause we are looking for |
|---|---|---|
| The vehicle search takes too long. | Response times for the assumed 46 searches per second from step 3 and an increased database. Aim: 95% of searches take a maximum of one second. | Does a query take a lot of time? Is a suitable index missing? Is the application or database busy? |
| Many people reserve the same vehicle. | Duration of reservation attempts, database lock wait times and effective assignments for the same period. | Are the requests waiting for the same assignment for a long time? A quick rejection due to an existing reservation is an expected domain conflict. |
| The reservation is waiting for payment verification. | Measure the wait from a job becoming due until it starts, separately from the subsequent provider-call duration. | Is the worker keeping up, or is the payment provider responding slowly? The appropriate measure depends on it. |
The vehicle search takes too long.
- What we measure
- Response times for the assumed 46 searches per second from step 3 and an increased database. Aim: 95% of searches take a maximum of one second.
- What cause we are looking for
- Does a query take a lot of time? Is a suitable index missing? Is the application or database busy?
Many people reserve the same vehicle.
- What we measure
- Duration of reservation attempts, database lock wait times and effective assignments for the same period.
- What cause we are looking for
- Are the requests waiting for the same assignment for a long time? A quick rejection due to an existing reservation is an expected domain conflict.
The reservation is waiting for payment verification.
- What we measure
- Measure the wait from a job becoming due until it starts, separately from the subsequent provider-call duration.
- What cause we are looking for
- Is the worker keeping up, or is the payment provider responding slowly? The appropriate measure depends on it.
We compare each measurement with the associated goal. A slow workflow alone does not justify an additional component. First, we determine the place where time is lost.
Making a decision for each situation
Further reading
Improve queries and indices first
The startup design searches directly in the relational SQL database. We check the queries for location, time period and vehicle. A search cache would cache results and answer repeated searches faster.
- Trade-off
- A cache saves database work, but can still display a vehicle that is now occupied as available. When we supplement it, we set a permitted display age. When booking, the database continues to check the occupancy bindingly. Faster display and possible disappointment when booking are weighed together.
- Reassess
- A cache is checked if recurrent searches fail the one-second target for 95% of searches despite improved queries, and measurements can be expected to benefit from reuse.
Check the occupancy jointly and in a short transaction
Checking and reservation must be protected together from competing accesses. The transaction contains only the necessary database work for this. The worker then executes external calls as described in step 7.
- Trade-off
- Protection prevents conflicting promises. Competing requests may have to wait for a short time or receive a rejection. We accept this restriction for a reliable booking. More API instances can handle more requests; the contention for the same vehicle remains.
- Reassess
- If waiting times are too long, we investigate transaction duration, locks and repeated attempts. The rule remains: for the same period, at most one effective occupancy may arise.
Start with order table and worker
The worker takes over stored orders from the SQL database. If independent orders wait too long for them to start, we check additional workers. A message broker would be its own service for receiving and distributing messages to such processors.
- Trade-off
- The order table keeps the start draft manageable, but claims the database. More workers need secure job claiming and repeatable processing. A broker offers additional distribution functions and incurs its own operational expense. A slow provider must continue to be treated separately.
- Reassess
- Additional workers are tested with proven processing backlog. A broker comes into consideration if order management measurably burdens the database or independent processors require separate queues. Allowed waiting times and reactions are specified in step 9.
Linking further expansion steps to specific boundaries
Further reading
- Move the reading load to a database copy
- Replication holds additional copies of a database. A read copy can take over search queries if their load overwhelms the primary database. In the case of asynchronous updating, it can be behind the current booking status. Binding reservation decisions therefore remain with the authoritative datastore. The additional copy relieves read accesses; write accesses remain with the responsible node.
- Offload expensive searches selectively
- For radius or full-text search, we first check the capabilities of the existing database. A separate search index becomes interesting if new search requirements or measured response times are not sufficiently met. For this, we have to keep another database up-to-date, monitor and rebuild it if necessary.
- Partition booking data only when measurements justify it
- Sharding distributes different parts of the data set to several responsible database nodes. The previous burden assumptions do not yet justify this effort. If write load or data volume exceeds the capacity of a suitable node despite optimization, we check a division: by vehicle ID, its occupancy remains together; by region, local accesses remain together. For this purpose, searches over several sub-stocks or vehicle changes between regions become more complex. A particularly sought-after vehicle remains a possible bottleneck even in a sub-stock.
Terms in this step
- Bottleneck
- A point that limits a workflow’s throughput or response time. Here, for example, the search query, the competing occupancy test or the worker come into question.
- Trade-off
- A conscious balance between advantage and disadvantage. A search cache can speed up answers, while its hits become obsolete in the meantime.
- Sharding
- The division of a data set among several responsible database nodes. A distribution by vehicle ID keeps the occupancy of the same vehicle together.
Try it yourself
A due payment order waits eight seconds for a free worker. The provider call then lasts 120 ms. Which cause do you investigate first, which measure do you examine and which disadvantage do you accept?
A hint for your attempt
Decomposes the total time into waiting before the start and execution time at the provider.
Compare with a possible solution
- Cause
- The measured waiting time arises predominantly before the provider call. Check worker utilization, slow jobs, and picking up due orders.
- Action
- If the lack of capacity explains the backlog, test additional workers with limited parallelism and secure job claiming.
- Trade-off
- More workers cost resources and can reach provider limits. Remeasure backlog and total wait time, and check for duplicate effects.
Apply to your project
Transfer the chosen diagnostic path to your own architecture and formulate the reading that would trigger a later decision.