Skip to content

Demo 15: autoscaling under a cap (flash sale at 3 vs 8 replicas) - #18

Open
MAOFILHO wants to merge 2 commits into
mainfrom
demo15/autoscaling
Open

MAOFILHO wants to merge 2 commits into
mainfrom
demo15/autoscaling

Conversation

@MAOFILHO

Copy link
Copy Markdown
Owner

From a LinkedIn comment: run the same flash sale with a 3 and an 8 cap, compare checkout success rate and cost per 1,000 completed orders. Container Apps caps replicas, not nodes.

What

  • scripts/flash_sale.py: buyers sign up first (not timed), then each buys 1 item over and over. A failed checkout retries the same cart, so orders stay 1 item in both runs. top_up gives each run the same stock.
  • make flash-sale CAP=3 / CAP=8 (infra/autoscale_demo.py, Azure only): prints the maximum cost and asks first, sets max replicas, switches inventory's demo switches on only to restock (off in finally), waits for new revisions, runs the sale, reads Azure Monitor Replicas/Requests per revision through the 5-min cooldown, prices at list price (sale active, cooldown idle, plus MySQL), resets the cap to 3 in finally.
  • /patterns/autoscaling shows the saved runs. No run is recorded yet: the Azure run needs the owner's go-ahead, then the results, a screenshot and the README section follow in this PR.

Tests

  • 11 new unit tests (summary, metric parsing across revisions and empty minutes, cost split, estimate, top-up, buyer retries the same cart). Repo unit suite: 71 passed.
  • Local smoke: 29 passed, 7 skipped (Azure). Local check with payment failing for 6 s: 1,179 failed checkouts, all 522 completed orders 1 item.

🤖 Generated with Claude Code

MAOFILHO and others added 2 commits November 18, 2026 20:37
…8 replicas

From a LinkedIn comment: run the same flash sale with a low and a high cap and compare checkout
success rate and cost per 1,000 completed orders. Container Apps caps replicas, not nodes.

- scripts/flash_sale.py: signs buyers up (not timed), then each buys 1 item over and over. A failed
  checkout retries the same cart, so every order is 1 item in both runs. top_up gives every run the
  same starting stock. Works locally and against Azure.
- infra/autoscale_demo.py (make flash-sale CAP=3|8, Azure only): prints the most the run can cost
  and asks first; sets every service's max replicas; turns inventory's switches on only to top up
  (off again in finally); waits for every new revision; runs the sale; reads Azure Monitor replicas
  and requests per revision through the 5-min cooldown; prices sale time active, cooldown idle, plus
  MySQL, at list price; puts the cap back to 3 in finally; saves flashSaleResults.json.
- Demo page /patterns/autoscaling shows the recorded runs side by side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lf the cost per 1,000

- Cap 3: 50.3% of checkouts succeeded (1,289 orders), $0.032, $0.025 per 1,000 orders.
- Cap 8: 99.2% (5,193 orders), $0.067, $0.013 per 1,000 orders.
- Fixes found in the run: sign-up retries a busy user service (it is not timed), and a buyer whose
  earlier checkout went through after a timeout (404, no open order) starts a new cart.
- README section, screenshot, 404 label on the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant