MSK Cost Optimizer
What this skill does
Optimises Amazon MSK cost across seven dimensions: broker type right-
sizing, Graviton broker migration, broker count optimisation, EBS storage
optimisation, MSK Serverless vs provisioned fit, partition count impact,
and data retention optimisation. Emits a deterministic verdict per cluster
with estimated monthly savings and a one-dimension-per-window migration
plan.
STRICT output contract
Every invocation MUST emit exactly one optimisation block per cluster
in this shape — no prose before, no commentary after:
TARGET: <cluster-name or cluster-arn>
VERDICT: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL
REASON: <1-2 sentences naming the recommendation and supporting data>
RECOMMENDATION:
Current: <broker-type, broker-count, EBS-volume, partitions,
retention, pricing model, Kafka version, tier>
Proposed: <per-dimension list of changes>
Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>
ESTIMATED_SAVINGS:
Monthly (broker right-sizing): $<amount>
Monthly (Graviton migration): $<amount>
Monthly (broker count reduction): $<amount>
Monthly (EBS storage): $<amount>
Monthly (serverless fit): $<amount>
Monthly (retention / compaction): $<amount>
Monthly (partition right-sizing): $0 (operational, no direct cost)
Annual total: $<amount>
Assumptions: <pricing region, 730h/month, etc.>
MIGRATION_STEPS:
1. <specific action with CLI command>
2. <verification step>
CONFIRM: Before executing any state-changing CLI, emit and await operator
approval: "CONFIRM: About to <action> on <cluster>. Proceed? (yes/no)"
A block missing VERDICT, RECOMMENDATION, ESTIMATED_SAVINGS, or
MIGRATION_STEPS is a contract violation — re-emit the full block.
FORBIDDEN output patterns
NEVER emit VERDICT: OPPORTUNITY_FOUND with Annual total: $0.
If all seven dimensions net zero savings, the verdict MUST be
ALREADY_OPTIMAL. A cost-neutral operational improvement (e.g.,
partition right-sizing) is surfaced in REASON, not as a dollar
saving.
NEVER show savings math that does not balance. The sum of all
Monthly (...) lines MUST equal the Monthly total, and
Monthly total × 12 MUST equal Annual total, rounded to 2 decimal
places. Re-verify before emitting.
NEVER recommend Graviton brokers (kafka.m7g) without confirming
Kafka version 3.x or later. Kafka 2.x does NOT support Graviton
broker types. Recommending Graviton on a Kafka 2.x cluster without
first planning the version upgrade will fail at cluster creation.
NEVER recommend reducing MSK broker count below 3. Kafka requires
a minimum of 3 brokers for replication factor=3 and quorum-based
fault tolerance. A 2-broker cluster cannot survive a single broker
failure without data loss.
NEVER recommend decreasing EBS volume size in-place. MSK supports
online EBS volume increases via update-broker-storage, but NOT
decreases. EBS reduction requires blue/green cluster migration. Flag
it for the next migration window, never as an immediate action.
NEVER recommend MSK Serverless for a workload exceeding 50 MB/s
sustained ingress without computing the full 30-day break-even
cost. Serverless per-partition-hour + per-GB data pricing exceeds
provisioned broker cost at high sustained throughput.
NEVER omit the CONFIRM: gate before any state-changing CLI
command. Every create-cluster-v2, update-cluster-configuration,
update-broker-storage, delete-cluster, and kafka-configs --alter
MUST be preceded by a CONFIRM line and operator approval.
NEVER emit scratch or recompute text ("WAIT", "let me redo",
"corrected:") in the output block. Finalize all math before emitting
the block.
Quick start
Core quick-start heuristics (Graviton ~20% cheaper on Kafka 3.x, Serverless break-even ~50 MB/s, minimum 3 brokers, EBS and retention cost drivers): moved verbatim to references/advanced-patterns.md.
The decision tables in Steps 4-10 below encode the same thresholds.
Mindset
Cost-structure fundamentals (how MSK cost differs from databases): moved verbatim to references/advanced-patterns.md.
The verdict thresholds below assume them.
Quick reference — verdict thresholds
| Observation |
Verdict |
Dimension |
| Cluster on kafka.m5 (pre-Graviton), Kafka 3.x+ |
OPPORTUNITY_FOUND |
Graviton migration |
| BytesInPerSec per broker avg < 10 MB/s on kafka.m5.2xlarge+ |
OPPORTUNITY_FOUND |
Broker right-sizing |
| Broker count > 3, total ingress < 50 MB/s, partitions < 400/broker |
OPPORTUNITY_FOUND |
Broker count reduction |
| KafkaDataLogsDiskUsed avg < 30% on 1 TB+ EBS volumes |
OPPORTUNITY_FOUND |
EBS storage |
| Total ingress < 50 MB/s with idle periods, provisioned |
OPPORTUNITY_FOUND |
Serverless fit |
| Log retention > 168h on high-throughput, non-compacted topic |
OPPORTUNITY_FOUND |
Retention |
| Partition count > 1000 total with low throughput per partition |
OPPORTUNITY_FOUND |
Partition right-sizing |
| All seven dimensions at cost-optimal config |
ALREADY_OPTIMAL |
(continue monitoring) |
Pre-flight: data gate (run before any optimisation decision)
MSK optimisation requires four data sources: Cost Explorer for billing
line items, cluster configuration (broker type, count, EBS, partitions,
retention), CloudWatch metrics for utilisation, and topic-level
configuration.
Required data sources
The four data-gathering command blocks (Cost Explorer breakdown, cluster configuration, CloudWatch metrics, topic configuration): moved verbatim to references/diagnostic-commands.md.
Run them before any optimisation decision, then apply the data-quality short-circuits below.
Data-quality short-circuits
| Condition |
Effect on optimisation |
| Cost Explorer access denied |
NEED_MORE_INFO for cost quantification; topology still analysable. |
| Observation window < 14 days |
NEED_MORE_INFO: workload may reflect atypical load. Min 14 days; 30 preferred. |
Cluster in CREATING / UPDATING / MAINTENANCE |
Wait for ACTIVE before emitting a change recommendation. |
| MSK Serverless cluster (no broker type) |
Skip broker right-size + count dimensions; analyse per-partition pricing. |
| Kafka version < 3.0 |
Graviton brokers not available; note version upgrade prerequisite. |
| Multi-VPC or cross-region replication active |
Each region's cluster bills independently; analyse separately. |
Process — Optimisation logic (apply in order)
Step 0: Non-obvious behaviours that change the recommendation
Non-obvious behaviours that change the recommendation (Graviton/Kafka-version coupling, broker-count immutability, EBS one-way scaling, Serverless billing model, partition overhead, compaction, Express tier, KRaft, retention): moved verbatim to references/advanced-patterns.md.
Load before emitting any recommendation; Steps 1-11 assume these constraints.
Step 1: Validate input and data sufficiency
If Cost Explorer access is unavailable AND the caller has not pasted
billing line items, emit NEED_MORE_INFO:
Fallback data-gathering commands when Cost Explorer is unavailable: moved verbatim to references/diagnostic-commands.md.
If neither CE access nor pasted data exists, emit NEED_MORE_INFO.
Step 2: Cost Explorer reconciliation
Cost Explorer reconciliation command block: moved verbatim to references/diagnostic-commands.md.
The USAGE_TYPE classification table stays below.
| USAGE_TYPE |
Dimension |
What it represents |
MSK:BrokerUsage |
Compute (provisioned) |
Per-broker-hour by type |
MSK:ServerlessUsage |
Compute (Serverless) |
Per-partition-hour + per-GB data |
MSK:EBSUsage |
EBS storage |
Per-GB-month of broker-attached volume |
If MSK:BrokerUsage dominates with kafka.m5 brokers, the Graviton
migration is the first lever. If MSK:EBSUsage is > 30% of total, the
retention/storage dimension has high leverage.
Step 3: Cost classification
| Cost profile |
Indicators |
Emphasis |
| Pre-Graviton |
kafka.m5 brokers, Kafka 3.x+ |
Graviton migration (Step 5) |
| Over-provisioned brokers |
BytesInPerSec/broker < 10 MB/s on large type |
Broker right-sizing (Step 4) |
| Excess broker count |
> 3 brokers, total ingress < 50 MB/s |
Broker count (Step 7) |
| EBS over-allocated |
KafkaDataLogsDiskUsed avg < 30% |
EBS storage (Step 8) |
| Serverless candidate |
Ingress < 50 MB/s, idle periods |
Serverless fit (Step 6) |
| Retention-driven storage |
EBSUsage high, retention > 168h |
Retention (Step 9) |
| Partition-heavy |
> 400 partitions/broker, low throughput |
Partition right-sizing (Step 10) |
| Mixed (no single dimension dominant) |
Even distribution |
Apply all in parallel |
Step 4: Broker type right-sizing
Decision matrix:
| Throughput profile (30-day) |
Recommendation |
Savings estimate |
| BytesInPerSec/broker avg < 5 MB/s on kafka.m5.2xlarge |
Downsize to kafka.m5.large or kafka.m7g.large |
~50% of compute |
| BytesInPerSec/broker avg 5-20 MB/s |
Keep current broker type |
None |
| BytesInPerSec/broker avg > 30 MB/s frequently |
Upsize or add brokers |
None — already constrained |
| CpuUser + CpuSystem avg > 60% |
CPU-bound; don't downsize |
None |
| Consumer lag (MaxOffsetLag) growing |
Throughput-bound; don't downsize |
None |
Worked example (m5.2xlarge right-sizing math): moved verbatim to references/worked-examples.md.
Apply the decision matrix above to reproduce it.
Step 5: Graviton broker migration
This is the highest-leverage dimension when the cluster is on kafka.m5
and Kafka version is 3.x+.
| Current |
Target |
Savings |
Notes |
| kafka.m5.large ($0.276/h) |
kafka.m7g.large ($0.22/h) |
~20% |
Same 2 vCPU / 8 GB |
| kafka.m5.2xlarge ($0.552/h) |
kafka.m7g.2xlarge ($0.44/h) |
~20% |
Same 8 vCPU / 32 GB |
| kafka.m5.4xlarge ($1.104/h) |
kafka.m7g.4xlarge ($0.88/h) |
~20% |
Same 16 vCPU / 64 GB |
| kafka.c5.large (legacy) |
kafka.m7g.large |
~15% |
c5 → m7g class change |
Worked example (Graviton migration savings math): moved verbatim to references/worked-examples.md.
Apply the migration matrix above to reproduce it.
Step 6: MSK Serverless vs provisioned fit evaluation
Serverless eliminates broker management and bills per partition-hour +
per-GB data + per-PUT-hour. The break-even calculation compares total
provisioned cost against projected Serverless pricing.
Break-even logic:
Serverless break-even calculation block: moved verbatim to references/worked-examples.md.
Break-even heuristic: below ~50 MB/s sustained ingress Serverless is usually cheaper.
A rough heuristic: if the provisioned cluster's total sustained ingress
is below ~50 MB/s, or if the cluster idles for extended periods,
Serverless is likely cheaper. Above 50 MB/s steady, provisioned with
Graviton brokers is cheaper.
| Provisioned profile |
Recommendation |
Rationale |
| Ingress < 50 MB/s, variable load |
Migrate to Serverless |
Pay only for partitions + data |
| Ingress < 50 MB/s, steady, few partitions |
Evaluate Serverless |
Break-even zone; compute 30-day cost |
| Ingress > 50 MB/s steady |
Keep provisioned + Graviton |
Provisioned cheaper at scale |
| > 1000 partitions |
Keep provisioned |
Serverless per-partition-hour adds up |
| Dev/test, idle nights/weekends |
Migrate to Serverless |
Near-zero cost when idle |
Worked example (Serverless vs provisioned math): moved verbatim to references/worked-examples.md.
Apply the fit table above to reproduce it.
Step 7: Broker count optimisation
| Observation |
Recommendation |
Savings |
| Broker count=6, total ingress < 50 MB/s, partitions < 120 |
Reduce to 3 brokers (blue/green migration) |
~50% of compute |
| Broker count=3, ingress > 50 MB/s, consumer lag growing |
Add brokers (scale out) |
None — capacity-bound |
| Broker count=3 (minimum for HA) |
Keep; cannot reduce below 3 |
None |
| Broker count > 3 with replication factor=3 |
Evaluate reducing to 3 if throughput allows |
Per excess broker |
Worked example (6-to-3 broker reduction math): moved verbatim to references/worked-examples.md.
Apply the observation table above to reproduce it.
Step 8: EBS storage optimisation
| Observation |
Recommendation |
Savings |
| KafkaDataLogsDiskUsed avg < 30% on 1 TB+ volumes |
Reduce volume on next blue/green |
Per-GB-month saved |
| KafkaDataLogsDiskUsed growing > 10%/month |
Enable MSK storage auto-expand |
Prevents volume exhaustion |
| Fixed volume with predictable growth |
Evaluate auto-expand vs manual right-size |
Operational savings |
| Volume per broker > 2x the data need |
Right-size to 1.3x actual usage |
~35% of EBS cost |
Worked example (EBS volume right-sizing math): moved verbatim to references/worked-examples.md.
Apply the observation table above to reproduce it.
Step 9: Data retention and compaction optimisation
| Observation |
Recommendation |
Savings |
| Retention > 168h on high-throughput non-compacted topic |
Reduce to 24-72h if replay not needed |
Up to 7x storage |
| Compaction candidate (changelog, event-sourcing) with time retention |
Switch to cleanup.policy=compact |
10x storage reduction |
| Mixed retention policy, some topics overly long |
Audit topic-level configs; standardise |
Variable |
| Retention = -1 (infinite) on any topic |
Set finite retention immediately |
Prevents unbounded growth |
Worked example (retention and compaction math): moved verbatim to references/worked-examples.md.
Apply the observation table above to reproduce it.
Step 10: Partition count right-sizing
| Observation |
Recommendation |
Savings |
| > 400 partitions/broker with low throughput/partition |
Consolidate partitions (operational) |
Enables broker downsize |
| 1000 partitions for a 1 MB/s workload |
Reduce to 12-24 partitions |
Frees broker CPU |
| Uneven partition distribution |
Reassign partitions (kafka-reassign-partitions) |
Performance, not cost |
| Consumer group reading from few partitions |
Reduce partition count to match consumer parallelism |
Enables downsize |
Partition right-sizing has no direct cost savings, but reducing
excessive partitions frees broker CPU and memory, which can then enable
a broker type downsize. This is a force-multiplier for Step 4.
Step 11: Final verdict
The verdict is the worst-case (most-actionable) finding across all
seven dimensions:
- If ANY dimension has a concrete recommendation with quantified
savings, verdict is OPPORTUNITY_FOUND.
- If a change was applied and verified this session, verdict is
OPTIMIZED.
- If all dimensions are at cost-optimal config AND broker count,
retention, and Serverless fit have been evaluated, verdict is
ALREADY_OPTIMAL.
Output format
Worked example — multi-dimension opportunity
TARGET: events-prod-msk
VERDICT: OPPORTUNITY_FOUND
REASON: Cluster runs kafka.m5.large (pre-Graviton) with 6 brokers,
1 TB EBS per broker at 25% disk used, 168h retention on a
high-throughput topic that only needs 24h, total ingress 15 MB/s
(well under the 50 MB/s Serverless break-even candidate range),
and Kafka 3.5.1 (Graviton-ready). Five dimensions have actionable
opportunities.
RECOMMENDATION:
Current:
Brokers: 6 x kafka.m5.large ($0.276/h) = $1,209/month
EBS: 6 x 1 TB gp3 = $480/month
Retention: 168h (7 days) on events topic
Partitions: 120 across 15 topics
Pricing: On-Demand (no commit)
Proposed:
- Graviton migration: kafka.m5.large -> kafka.m7g.large ($0.22/h,
20% cheaper). Kafka 3.5.1 supports Graviton.
- Broker count: reduce 6 -> 3 brokers (blue/green migration).
Total ingress 15 MB/s is 5 MB/s/broker on 3 brokers — well within
capacity. Partition ratio 40/broker (under 400 ceiling).
- EBS: reduce 1 TB -> 500 GB per broker on new cluster (disk used
is 25% = 250 GB; 500 GB gives 2x headroom). Enable auto-expand.
- Retention: reduce events topic from 168h -> 24h (data-replay
requirement is 24h).
- Combined: migrate to kafka.m7g.large x 3 brokers with 500 GB EBS
and 24h retention in a single blue/green migration.
Confidence: HIGH — CloudWatch confirms low disk utilisation; CE
confirms On-Demand spend with no discount; Kafka version supports
Graviton.
ESTIMATED_SAVINGS:
Monthly (Graviton migration): $122 (3 x ($0.276-$0.22) x 730)
Monthly (broker count 6->3): $604 (3 x $0.276 x 730)
Monthly (EBS 1TB->500GB): $120 (3 x 500GB x $0.08)
Monthly (retention 168h->24h): $411 (storage delta on events topic)
Annual total: $15,084
Assumptions: us-east-1 pricing, 730h/month, all changes applied via
blue/green migration to a new cluster.
MIGRATION_STEPS:
1. Snapshot current topic configurations and consumer group offsets:
aws kafka describe-cluster-v2 --cluster-arn $CLUSTER_ARN
# Record partition count, replication factor, retention per topic
2. Create the new MSK cluster with optimised config:
aws kafka create-cluster-v2 \
--cluster-name events-prod-msk-v2 \
--provisioned '{"BrokerNodeGroupInfo":{\
"InstanceType":"kafka.m7g.large",\
"BrokerCount":3,\
"StorageInfo":{"VolumeSize":500}},\
"KafkaVersion":"3.5.1"}'
3. Set retention to 24h on the events topic in the new cluster:
kafka-configs --bootstrap-server $NEW_BROKERS \
--alter --topic events \
--add-config retention.ms=86400000
4. Sync data via MirrorMaker2 or MSK Cluster Linking:
# Start MirrorMaker2 to replicate topics from old -> new cluster
5. Cut over producers and consumers to the new cluster.
6. Verify BytesInPerSec, KafkaDataLogsDiskUsed, and MaxOffsetLag
are stable for 7 days on the new cluster.
7. Decommission the old cluster:
aws kafka delete-cluster --cluster-arn $OLD_CLUSTER_ARN
CONFIRM: Before each state-changing CLI, emit and await operator
approval. Stage the blue/green migration with monitoring between
each step; never batch the cut-over + decommission.
Worked example — already optimal
Full worked example for an ALREADY_OPTIMAL verdict: moved verbatim to references/worked-examples.md.
The multi-dimension example above is the primary contract demonstration.
Anti-Patterns — NEVER do these things
NEVER recommend reducing MSK broker count below 3. Kafka requires
a minimum of 3 brokers for replication factor=3 and quorum-based
fault tolerance. A 2-broker cluster cannot survive a single broker
failure without data loss. Always retain at least 3 brokers for HA.
NEVER recommend Graviton brokers without confirming Kafka version
3.x+. Kafka 2.x does not support Graviton (m7g/m6g) broker types.
Recommending Graviton on a Kafka 2.x cluster without first planning
the version upgrade will fail at cluster creation.
NEVER recommend decreasing EBS volume size in-place. MSK supports
online EBS volume increases via update-broker-storage, but NOT
decreases. Decreasing EBS requires cluster recreation via blue/green
migration. Always flag EBS reduction for the next migration, not as
an immediate action.
NEVER recommend MSK Serverless for a workload exceeding 50 MB/s
sustained ingress without computing the full break-even. Serverless
per-partition-hour + per-GB data pricing exceeds provisioned broker
cost at high sustained throughput. Always compute the 30-day projected
Serverless cost and compare against provisioned + Graviton cost.
NEVER recommend reducing log retention without confirming the
data-replay requirement. Consumers may depend on historical data
for batch processing, backfill, or audit. Always confirm the required
replay window before shortening retention. For audit requirements,
consider exporting to S3 before reducing Kafka-side retention.
NEVER recommend switching a topic to cleanup.policy=compact without
confirming the topic is key-based. Compaction on a topic with null
keys or append-only events will delete data unpredictably.
NEVER recommend adding partitions to solve a throughput problem
without checking the consumer parallelism first. More partitions add
broker overhead; if consumers can't parallelise, the partitions are
wasted cost.
NEVER batch a blue/green migration's cut-over and decommission in
one step. Always cut over, verify for 7 days, then decommission the
old cluster.
NEVER purchase a 3-year commitment on a cluster with active migration
plans. The commitment outlasts the cluster. Match commit term to
expected cluster lifetime.
NEVER recommend MSK Express tier for a steady-state workload. Express
burst credits deplete under sustained load; Express is for variable-
throughput workloads that burst occasionally.
Quick navigation
| You want to... |
Jump to |
| Evaluate Graviton migration (m5 -> m7g) |
Step 5 — Graviton migration |
| Right-size broker type |
Step 4 — Broker right-sizing |
| Reduce broker count (6 -> 3) |
Step 7 — Broker count optimisation |
| Evaluate MSK Serverless vs provisioned |
Step 6 — Serverless fit |
| Optimise EBS storage |
Step 8 — EBS storage optimisation |
| Reduce log retention / enable compaction |
Step 9 — Retention and compaction |
| Reduce excessive partitions |
Step 10 — Partition right-sizing |
| Handle missing data |
Step 1 — Validate input |
| Look up pricing / broker types |
references/msk-pricing-reference.md |
Expert heuristic — the 60-second triage
The 60-second triage (six checks to run when handed an MSK bill): moved verbatim to references/advanced-patterns.md.
If any check hits, deep-dive the corresponding Process step.
Pre-flight safety checks (run before any remediation CLI)
Pre-flight safety checks (confirmation gate, state recording, one-dimension-per-window, post-change verification, blue/green migration, 3-cluster batch limit): moved verbatim to references/diagnostic-commands.md.
NEVER omit the CONFIRM gate — see FORBIDDEN output patterns above.
Verdict semantics
| Verdict |
When to emit |
Position in workflow |
OPPORTUNITY_FOUND |
At least one dimension has a savings-bearing recommendation. |
Primary — terminal for actionable findings. |
OPTIMIZED |
A change was applied and verified this session; CE line items confirm the new pattern. |
Primary — only emitted post-remediation. |
ALREADY_OPTIMAL |
All seven dimensions at cost-optimal config AND broker count, retention, and Serverless fit evaluated. |
Primary — terminal for healthy findings. |
NEED_MORE_INFO |
Data gate failed: CE access denied, CloudWatch window < 14 days, Kafka version unknown. |
Pre-decision — emit per-dimension; other dimensions can still emit OPPORTUNITY_FOUND. |
Recent AWS features (2024-2026)
Recent AWS features (2024-2026): moved verbatim to references/advanced-patterns.md.
Check before recommending Express tier, KRaft, or the newest broker types.
AWS documentation
Domain: AWS CloudOps / Analytics — Amazon MSK cost optimisation.
References (load on demand)
- references/advanced-patterns.md — Step 0 non-obvious behaviours, quick-start heuristics, cost-structure fundamentals, 60-second triage, recent AWS features (2024-2026).
- references/diagnostic-commands.md — Required data-source commands, Step 1/Step 2 command blocks, pre-flight safety checks.
- references/worked-examples.md — Secondary worked examples (right-sizing, Graviton, Serverless break-even, broker count, EBS, retention, already-optimal).
- references/msk-pricing-reference.md — Broker-type pricing, Graviton savings matrix, Serverless pricing, EBS and retention cost projections.
1---2name: msk-cost-optimizer3description: Optimises Amazon MSK cost across seven dimensions — broker type right-sizing (CloudWatch BytesInPerSec, KafkaDataLogsDiskUsed, consumer lag MaxOffsetLag), broker count optimisation (minimum 3 for HA, reduce excess on low-throughput clusters), EBS storage optimisation (storage-auto-scaling vs fixed gp3, right-size to retention needs), MSK Serverless vs provisioned (break-even ~50 MB/s ingress), partition count impact (excessive partitions add broker overhead), data retention optimisation (log retention hours, compacted topics for changelog workloads), and Graviton broker migration (Kafka 3.x, kafka.m7g ~20% cheaper). Covers MSK Cluster Tier (Express) and MSK with KRaft. Emits OPTIMIZED, OPPORTUNITY_FOUND, or ALREADY_OPTIMAL per cluster with estimated monthly savings.4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). Offline classification works from pasted cluster configuration, CloudWatch summaries, and billing line items. Live-account optimisation uses aws kafka describe-cluster, describe-cluster-v2, list-clusters-v2, aws kafka describe-configuration, aws cloudwatch get-metric-statistics for AWS/Kafka BytesInPerSec, BytesOutPerSec, KafkaDataLogsDiskUsed, ConsumerLagMetrics MaxOffsetLag, CpuUser, CpuSystem, aws ce...6metadata:7 source: https://skillmd.com/skills/jhkchan/msk-cost-optimizer8 domain: aws-cloudops9 complexity: high10 requires_llm: 'true'11 phase: '3'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Analytics15 task_type: optimize16 skill_class: capability17 lifecycle_status: active18 verdict_shape: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL19 when_to_use: Reviewing Amazon MSK cluster spend, right-sizing Kafka broker types, evaluating Graviton brokers (kafka.m7g vs kafka.m5), deciding between MSK Serverless and provisioned (break-even ~50 MB/s), optimising broker count (minimum 3 for HA, reduce excess), auditing EBS storage allocation vs actual disk usage, tuning log retention hours or compacted topics for storage savings, or evaluating MSK Cluster Tier (Express) and MSK with KRaft for cost.20 when_not_to_use: Self-managed Kafka on EC2 cost optimisation (this skill covers the managed MSK service only), Kafka Connect or MSK Connect cost optimisation (use kafka-connect-troubleshooter or a Connect specialist), Kinesis Data Streams cost optimisation (different service), Kafka performance tuning or partition rebalancing as the primary goal (use a Kafka operations workflow; this skill uses metrics only to identify cost waste), or MSK security or TLS configuration (use a security audit workflow).21 activation_triggers: optimise MSK cost, right-size MSK broker, MSK Graviton migration, kafka.m7g vs kafka.m5, MSK Serverless vs provisioned, MSK broker count, MSK EBS storage optimisation, MSK log retention, MSK compacted topics, MSK partition count, MSK Cluster Tier Express, MSK KRaft, MSK consumer lag cost, KafkaDataLogsDiskUsed, reduce MSK bill22 invocation_schema: 'Input: either (a) an MSK cluster ARN or identifier + live-account context, (b) a cluster configuration document (broker type, broker count, EBS volume size, partition count, retention hours, Kafka version, pricing model, CloudWatch metrics), OR (c) a fleet description for batch optimisation. Output: a deterministic TARGET / VERDICT / REASON / RECOMMENDATION / ESTIMATED_SAVINGS / MIGRATION_STEPS block per cluster, where VERDICT ∈ {OPTIMIZED, OPPORTUNITY_FOUND, ALREADY_OPTIMAL}.'23 invocation_example: "# Minimal valid input (offline classification):\nCluster: events-prod-msk\nKafka Version: 3.5.1\nRegion: us-east-1\nBroker Type: kafka.m5.large (2 vCPU, 8 GB)\nBroker Count: 6\nEBS Volume: 1 TB gp3 per broker\nPartitions: 120 across 15 topics\nLog Retention: 168 hours (7 days)\nCompacted Topics: none\nPricing: On-Demand (no commit)\nCloudWatch metrics (last 30 days):\n - BytesInPerSec per broker: avg=5, max=12\n - KafkaDataLogsDiskUsed: avg=25%, max=35%\n - MaxOffsetLag: avg=1,000 (low consumer lag)\nEmit the standard optimisation block (TARGET, VERDICT, REASON,\nRECOMMENDATION, ESTIMATED_SAVINGS, MIGRATION_STEPS)."24 version: 0.1.025 author: Jacky Chan — AWS Community Builder26 keywords: Amazon MSK, Amazon Managed Streaming for Apache Kafka, MSK Serverless, MSK Express, MSK Cluster Tier, MSK KRaft, Graviton brokers, kafka.m7g, broker right-sizing, EBS storage optimisation, log retention, compacted topics, partition count, consumer lag, KafkaDataLogsDiskUsed, data retention, FinOps, streaming cost27 tags: msk, kafka, analytics, cost-optimization, finops, right-sizing, serverless28---2930# MSK Cost Optimizer3132## What this skill does3334Optimises Amazon MSK cost across seven dimensions: broker type right-35sizing, Graviton broker migration, broker count optimisation, EBS storage36optimisation, MSK Serverless vs provisioned fit, partition count impact,37and data retention optimisation. Emits a deterministic verdict per cluster38with estimated monthly savings and a one-dimension-per-window migration39plan.4041## STRICT output contract4243Every invocation MUST emit exactly one optimisation block per cluster44in this shape — no prose before, no commentary after:4546```text47TARGET: <cluster-name or cluster-arn>48VERDICT: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL49REASON: <1-2 sentences naming the recommendation and supporting data>50RECOMMENDATION:51 Current: <broker-type, broker-count, EBS-volume, partitions,52 retention, pricing model, Kafka version, tier>53 Proposed: <per-dimension list of changes>54 Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>55ESTIMATED_SAVINGS:56 Monthly (broker right-sizing): $<amount>57 Monthly (Graviton migration): $<amount>58 Monthly (broker count reduction): $<amount>59 Monthly (EBS storage): $<amount>60 Monthly (serverless fit): $<amount>61 Monthly (retention / compaction): $<amount>62 Monthly (partition right-sizing): $0 (operational, no direct cost)63 Annual total: $<amount>64 Assumptions: <pricing region, 730h/month, etc.>65MIGRATION_STEPS:66 1. <specific action with CLI command>67 2. <verification step>68CONFIRM: Before executing any state-changing CLI, emit and await operator69 approval: "CONFIRM: About to <action> on <cluster>. Proceed? (yes/no)"70```7172A block missing VERDICT, RECOMMENDATION, ESTIMATED_SAVINGS, or73MIGRATION_STEPS is a contract violation — re-emit the full block.7475### FORBIDDEN output patterns76771. **NEVER emit `VERDICT: OPPORTUNITY_FOUND` with `Annual total: $0`.**78 If all seven dimensions net zero savings, the verdict MUST be79 `ALREADY_OPTIMAL`. A cost-neutral operational improvement (e.g.,80 partition right-sizing) is surfaced in REASON, not as a dollar81 saving.82832. **NEVER show savings math that does not balance.** The sum of all84 `Monthly (...)` lines MUST equal the Monthly total, and85 `Monthly total × 12` MUST equal `Annual total`, rounded to 2 decimal86 places. Re-verify before emitting.87883. **NEVER recommend Graviton brokers (`kafka.m7g`) without confirming89 Kafka version 3.x or later.** Kafka 2.x does NOT support Graviton90 broker types. Recommending Graviton on a Kafka 2.x cluster without91 first planning the version upgrade will fail at cluster creation.92934. **NEVER recommend reducing MSK broker count below 3.** Kafka requires94 a minimum of 3 brokers for replication factor=3 and quorum-based95 fault tolerance. A 2-broker cluster cannot survive a single broker96 failure without data loss.97985. **NEVER recommend decreasing EBS volume size in-place.** MSK supports99 online EBS volume increases via `update-broker-storage`, but NOT100 decreases. EBS reduction requires blue/green cluster migration. Flag101 it for the next migration window, never as an immediate action.1021036. **NEVER recommend MSK Serverless for a workload exceeding 50 MB/s104 sustained ingress without computing the full 30-day break-even105 cost.** Serverless per-partition-hour + per-GB data pricing exceeds106 provisioned broker cost at high sustained throughput.1071087. **NEVER omit the `CONFIRM:` gate before any state-changing CLI109 command.** Every `create-cluster-v2`, `update-cluster-configuration`,110 `update-broker-storage`, `delete-cluster`, and `kafka-configs --alter`111 MUST be preceded by a CONFIRM line and operator approval.1121138. **NEVER emit scratch or recompute text** ("WAIT", "let me redo",114 "corrected:") in the output block. Finalize all math before emitting115 the block.116117## Quick start118119Core quick-start heuristics (Graviton ~20% cheaper on Kafka 3.x, Serverless break-even ~50 MB/s, minimum 3 brokers, EBS and retention cost drivers): moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).120The decision tables in Steps 4-10 below encode the same thresholds.121122## Mindset123124Cost-structure fundamentals (how MSK cost differs from databases): moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).125The verdict thresholds below assume them.126127## Quick reference — verdict thresholds128129| Observation | Verdict | Dimension |130|---|---|---|131| Cluster on kafka.m5 (pre-Graviton), Kafka 3.x+ | **OPPORTUNITY_FOUND** | Graviton migration |132| BytesInPerSec per broker avg < 10 MB/s on kafka.m5.2xlarge+ | **OPPORTUNITY_FOUND** | Broker right-sizing |133| Broker count > 3, total ingress < 50 MB/s, partitions < 400/broker | **OPPORTUNITY_FOUND** | Broker count reduction |134| KafkaDataLogsDiskUsed avg < 30% on 1 TB+ EBS volumes | **OPPORTUNITY_FOUND** | EBS storage |135| Total ingress < 50 MB/s with idle periods, provisioned | **OPPORTUNITY_FOUND** | Serverless fit |136| Log retention > 168h on high-throughput, non-compacted topic | **OPPORTUNITY_FOUND** | Retention |137| Partition count > 1000 total with low throughput per partition | **OPPORTUNITY_FOUND** | Partition right-sizing |138| All seven dimensions at cost-optimal config | **ALREADY_OPTIMAL** | (continue monitoring) |139140## Pre-flight: data gate (run before any optimisation decision)141142MSK optimisation requires four data sources: Cost Explorer for billing143line items, cluster configuration (broker type, count, EBS, partitions,144retention), CloudWatch metrics for utilisation, and topic-level145configuration.146147### Required data sources148149The four data-gathering command blocks (Cost Explorer breakdown, cluster configuration, CloudWatch metrics, topic configuration): moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).150Run them before any optimisation decision, then apply the data-quality short-circuits below.151152### Data-quality short-circuits153154| Condition | Effect on optimisation |155|---|---|156| Cost Explorer access denied | NEED_MORE_INFO for cost quantification; topology still analysable. |157| Observation window < 14 days | NEED_MORE_INFO: workload may reflect atypical load. Min 14 days; 30 preferred. |158| Cluster in `CREATING` / `UPDATING` / `MAINTENANCE` | Wait for `ACTIVE` before emitting a change recommendation. |159| MSK Serverless cluster (no broker type) | Skip broker right-size + count dimensions; analyse per-partition pricing. |160| Kafka version < 3.0 | Graviton brokers not available; note version upgrade prerequisite. |161| Multi-VPC or cross-region replication active | Each region's cluster bills independently; analyse separately. |162163## Process — Optimisation logic (apply in order)164165### Step 0: Non-obvious behaviours that change the recommendation166167Non-obvious behaviours that change the recommendation (Graviton/Kafka-version coupling, broker-count immutability, EBS one-way scaling, Serverless billing model, partition overhead, compaction, Express tier, KRaft, retention): moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).168Load before emitting any recommendation; Steps 1-11 assume these constraints.169170### Step 1: Validate input and data sufficiency171172If Cost Explorer access is unavailable AND the caller has not pasted173billing line items, emit NEED_MORE_INFO:174175Fallback data-gathering commands when Cost Explorer is unavailable: moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).176If neither CE access nor pasted data exists, emit NEED_MORE_INFO.177178### Step 2: Cost Explorer reconciliation179180Cost Explorer reconciliation command block: moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).181The USAGE_TYPE classification table stays below.182183| USAGE_TYPE | Dimension | What it represents |184|---|---|---|185| `MSK:BrokerUsage` | Compute (provisioned) | Per-broker-hour by type |186| `MSK:ServerlessUsage` | Compute (Serverless) | Per-partition-hour + per-GB data |187| `MSK:EBSUsage` | EBS storage | Per-GB-month of broker-attached volume |188189If `MSK:BrokerUsage` dominates with kafka.m5 brokers, the Graviton190migration is the first lever. If `MSK:EBSUsage` is > 30% of total, the191retention/storage dimension has high leverage.192193### Step 3: Cost classification194195| Cost profile | Indicators | Emphasis |196|---|---|---|197| Pre-Graviton | kafka.m5 brokers, Kafka 3.x+ | Graviton migration (Step 5) |198| Over-provisioned brokers | BytesInPerSec/broker < 10 MB/s on large type | Broker right-sizing (Step 4) |199| Excess broker count | > 3 brokers, total ingress < 50 MB/s | Broker count (Step 7) |200| EBS over-allocated | KafkaDataLogsDiskUsed avg < 30% | EBS storage (Step 8) |201| Serverless candidate | Ingress < 50 MB/s, idle periods | Serverless fit (Step 6) |202| Retention-driven storage | EBSUsage high, retention > 168h | Retention (Step 9) |203| Partition-heavy | > 400 partitions/broker, low throughput | Partition right-sizing (Step 10) |204| Mixed (no single dimension dominant) | Even distribution | Apply all in parallel |205206### Step 4: Broker type right-sizing207208**Decision matrix:**209210| Throughput profile (30-day) | Recommendation | Savings estimate |211|---|---|---|212| BytesInPerSec/broker avg < 5 MB/s on kafka.m5.2xlarge | Downsize to kafka.m5.large or kafka.m7g.large | ~50% of compute |213| BytesInPerSec/broker avg 5-20 MB/s | Keep current broker type | None |214| BytesInPerSec/broker avg > 30 MB/s frequently | Upsize or add brokers | None — already constrained |215| CpuUser + CpuSystem avg > 60% | CPU-bound; don't downsize | None |216| Consumer lag (MaxOffsetLag) growing | Throughput-bound; don't downsize | None |217218Worked example (m5.2xlarge right-sizing math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).219Apply the decision matrix above to reproduce it.220221### Step 5: Graviton broker migration222223This is the highest-leverage dimension when the cluster is on kafka.m5224and Kafka version is 3.x+.225226| Current | Target | Savings | Notes |227|---|---|---|---|228| kafka.m5.large ($0.276/h) | kafka.m7g.large ($0.22/h) | ~20% | Same 2 vCPU / 8 GB |229| kafka.m5.2xlarge ($0.552/h) | kafka.m7g.2xlarge ($0.44/h) | ~20% | Same 8 vCPU / 32 GB |230| kafka.m5.4xlarge ($1.104/h) | kafka.m7g.4xlarge ($0.88/h) | ~20% | Same 16 vCPU / 64 GB |231| kafka.c5.large (legacy) | kafka.m7g.large | ~15% | c5 → m7g class change |232233Worked example (Graviton migration savings math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).234Apply the migration matrix above to reproduce it.235236### Step 6: MSK Serverless vs provisioned fit evaluation237238Serverless eliminates broker management and bills per partition-hour +239per-GB data + per-PUT-hour. The break-even calculation compares total240provisioned cost against projected Serverless pricing.241242**Break-even logic:**243244Serverless break-even calculation block: moved verbatim to [references/worked-examples.md](references/worked-examples.md).245Break-even heuristic: below ~50 MB/s sustained ingress Serverless is usually cheaper.246247A rough heuristic: if the provisioned cluster's total sustained ingress248is below ~50 MB/s, or if the cluster idles for extended periods,249Serverless is likely cheaper. Above 50 MB/s steady, provisioned with250Graviton brokers is cheaper.251252| Provisioned profile | Recommendation | Rationale |253|---|---|---|254| Ingress < 50 MB/s, variable load | Migrate to Serverless | Pay only for partitions + data |255| Ingress < 50 MB/s, steady, few partitions | Evaluate Serverless | Break-even zone; compute 30-day cost |256| Ingress > 50 MB/s steady | Keep provisioned + Graviton | Provisioned cheaper at scale |257| > 1000 partitions | Keep provisioned | Serverless per-partition-hour adds up |258| Dev/test, idle nights/weekends | Migrate to Serverless | Near-zero cost when idle |259260Worked example (Serverless vs provisioned math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).261Apply the fit table above to reproduce it.262263### Step 7: Broker count optimisation264265| Observation | Recommendation | Savings |266|---|---|---|267| Broker count=6, total ingress < 50 MB/s, partitions < 120 | Reduce to 3 brokers (blue/green migration) | ~50% of compute |268| Broker count=3, ingress > 50 MB/s, consumer lag growing | Add brokers (scale out) | None — capacity-bound |269| Broker count=3 (minimum for HA) | Keep; cannot reduce below 3 | None |270| Broker count > 3 with replication factor=3 | Evaluate reducing to 3 if throughput allows | Per excess broker |271272Worked example (6-to-3 broker reduction math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).273Apply the observation table above to reproduce it.274275### Step 8: EBS storage optimisation276277| Observation | Recommendation | Savings |278|---|---|---|279| KafkaDataLogsDiskUsed avg < 30% on 1 TB+ volumes | Reduce volume on next blue/green | Per-GB-month saved |280| KafkaDataLogsDiskUsed growing > 10%/month | Enable MSK storage auto-expand | Prevents volume exhaustion |281| Fixed volume with predictable growth | Evaluate auto-expand vs manual right-size | Operational savings |282| Volume per broker > 2x the data need | Right-size to 1.3x actual usage | ~35% of EBS cost |283284Worked example (EBS volume right-sizing math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).285Apply the observation table above to reproduce it.286287### Step 9: Data retention and compaction optimisation288289| Observation | Recommendation | Savings |290|---|---|---|291| Retention > 168h on high-throughput non-compacted topic | Reduce to 24-72h if replay not needed | Up to 7x storage |292| Compaction candidate (changelog, event-sourcing) with time retention | Switch to cleanup.policy=compact | 10x storage reduction |293| Mixed retention policy, some topics overly long | Audit topic-level configs; standardise | Variable |294| Retention = -1 (infinite) on any topic | Set finite retention immediately | Prevents unbounded growth |295296Worked example (retention and compaction math): moved verbatim to [references/worked-examples.md](references/worked-examples.md).297Apply the observation table above to reproduce it.298299### Step 10: Partition count right-sizing300301| Observation | Recommendation | Savings |302|---|---|---|303| > 400 partitions/broker with low throughput/partition | Consolidate partitions (operational) | Enables broker downsize |304| 1000 partitions for a 1 MB/s workload | Reduce to 12-24 partitions | Frees broker CPU |305| Uneven partition distribution | Reassign partitions (kafka-reassign-partitions) | Performance, not cost |306| Consumer group reading from few partitions | Reduce partition count to match consumer parallelism | Enables downsize |307308Partition right-sizing has no direct cost savings, but reducing309excessive partitions frees broker CPU and memory, which can then enable310a broker type downsize. This is a force-multiplier for Step 4.311312### Step 11: Final verdict313314The verdict is the worst-case (most-actionable) finding across all315seven dimensions:316317- If ANY dimension has a concrete recommendation with quantified318 savings, verdict is **OPPORTUNITY_FOUND**.319- If a change was applied and verified this session, verdict is320 **OPTIMIZED**.321- If all dimensions are at cost-optimal config AND broker count,322 retention, and Serverless fit have been evaluated, verdict is323 **ALREADY_OPTIMAL**.324325## Output format326327### Worked example — multi-dimension opportunity328329```text330TARGET: events-prod-msk331VERDICT: OPPORTUNITY_FOUND332REASON: Cluster runs kafka.m5.large (pre-Graviton) with 6 brokers,333 1 TB EBS per broker at 25% disk used, 168h retention on a334 high-throughput topic that only needs 24h, total ingress 15 MB/s335 (well under the 50 MB/s Serverless break-even candidate range),336 and Kafka 3.5.1 (Graviton-ready). Five dimensions have actionable337 opportunities.338RECOMMENDATION:339 Current:340 Brokers: 6 x kafka.m5.large ($0.276/h) = $1,209/month341 EBS: 6 x 1 TB gp3 = $480/month342 Retention: 168h (7 days) on events topic343 Partitions: 120 across 15 topics344 Pricing: On-Demand (no commit)345 Proposed:346 - Graviton migration: kafka.m5.large -> kafka.m7g.large ($0.22/h,347 20% cheaper). Kafka 3.5.1 supports Graviton.348 - Broker count: reduce 6 -> 3 brokers (blue/green migration).349 Total ingress 15 MB/s is 5 MB/s/broker on 3 brokers — well within350 capacity. Partition ratio 40/broker (under 400 ceiling).351 - EBS: reduce 1 TB -> 500 GB per broker on new cluster (disk used352 is 25% = 250 GB; 500 GB gives 2x headroom). Enable auto-expand.353 - Retention: reduce events topic from 168h -> 24h (data-replay354 requirement is 24h).355 - Combined: migrate to kafka.m7g.large x 3 brokers with 500 GB EBS356 and 24h retention in a single blue/green migration.357 Confidence: HIGH — CloudWatch confirms low disk utilisation; CE358 confirms On-Demand spend with no discount; Kafka version supports359 Graviton.360ESTIMATED_SAVINGS:361 Monthly (Graviton migration): $122 (3 x ($0.276-$0.22) x 730)362 Monthly (broker count 6->3): $604 (3 x $0.276 x 730)363 Monthly (EBS 1TB->500GB): $120 (3 x 500GB x $0.08)364 Monthly (retention 168h->24h): $411 (storage delta on events topic)365 Annual total: $15,084366 Assumptions: us-east-1 pricing, 730h/month, all changes applied via367 blue/green migration to a new cluster.368MIGRATION_STEPS:369 1. Snapshot current topic configurations and consumer group offsets:370 aws kafka describe-cluster-v2 --cluster-arn $CLUSTER_ARN371 # Record partition count, replication factor, retention per topic372 2. Create the new MSK cluster with optimised config:373 aws kafka create-cluster-v2 \374 --cluster-name events-prod-msk-v2 \375 --provisioned '{"BrokerNodeGroupInfo":{\376 "InstanceType":"kafka.m7g.large",\377 "BrokerCount":3,\378 "StorageInfo":{"VolumeSize":500}},\379 "KafkaVersion":"3.5.1"}'380 3. Set retention to 24h on the events topic in the new cluster:381 kafka-configs --bootstrap-server $NEW_BROKERS \382 --alter --topic events \383 --add-config retention.ms=86400000384 4. Sync data via MirrorMaker2 or MSK Cluster Linking:385 # Start MirrorMaker2 to replicate topics from old -> new cluster386 5. Cut over producers and consumers to the new cluster.387 6. Verify BytesInPerSec, KafkaDataLogsDiskUsed, and MaxOffsetLag388 are stable for 7 days on the new cluster.389 7. Decommission the old cluster:390 aws kafka delete-cluster --cluster-arn $OLD_CLUSTER_ARN391CONFIRM: Before each state-changing CLI, emit and await operator392 approval. Stage the blue/green migration with monitoring between393 each step; never batch the cut-over + decommission.394```395396### Worked example — already optimal397398Full worked example for an ALREADY_OPTIMAL verdict: moved verbatim to [references/worked-examples.md](references/worked-examples.md).399The multi-dimension example above is the primary contract demonstration.400401## Anti-Patterns — NEVER do these things402403- **NEVER recommend reducing MSK broker count below 3.** Kafka requires404 a minimum of 3 brokers for replication factor=3 and quorum-based405 fault tolerance. A 2-broker cluster cannot survive a single broker406 failure without data loss. Always retain at least 3 brokers for HA.407408- **NEVER recommend Graviton brokers without confirming Kafka version409 3.x+.** Kafka 2.x does not support Graviton (m7g/m6g) broker types.410 Recommending Graviton on a Kafka 2.x cluster without first planning411 the version upgrade will fail at cluster creation.412413- **NEVER recommend decreasing EBS volume size in-place.** MSK supports414 online EBS volume increases via update-broker-storage, but NOT415 decreases. Decreasing EBS requires cluster recreation via blue/green416 migration. Always flag EBS reduction for the next migration, not as417 an immediate action.418419- **NEVER recommend MSK Serverless for a workload exceeding 50 MB/s420 sustained ingress without computing the full break-even.** Serverless421 per-partition-hour + per-GB data pricing exceeds provisioned broker422 cost at high sustained throughput. Always compute the 30-day projected423 Serverless cost and compare against provisioned + Graviton cost.424425- **NEVER recommend reducing log retention without confirming the426 data-replay requirement.** Consumers may depend on historical data427 for batch processing, backfill, or audit. Always confirm the required428 replay window before shortening retention. For audit requirements,429 consider exporting to S3 before reducing Kafka-side retention.430431- NEVER recommend switching a topic to cleanup.policy=compact without432 confirming the topic is key-based. Compaction on a topic with null433 keys or append-only events will delete data unpredictably.434- NEVER recommend adding partitions to solve a throughput problem435 without checking the consumer parallelism first. More partitions add436 broker overhead; if consumers can't parallelise, the partitions are437 wasted cost.438- NEVER batch a blue/green migration's cut-over and decommission in439 one step. Always cut over, verify for 7 days, then decommission the440 old cluster.441- NEVER purchase a 3-year commitment on a cluster with active migration442 plans. The commitment outlasts the cluster. Match commit term to443 expected cluster lifetime.444- NEVER recommend MSK Express tier for a steady-state workload. Express445 burst credits deplete under sustained load; Express is for variable-446 throughput workloads that burst occasionally.447448## Quick navigation449450| You want to... | Jump to |451|---|---|452| Evaluate Graviton migration (m5 -> m7g) | Step 5 — Graviton migration |453| Right-size broker type | Step 4 — Broker right-sizing |454| Reduce broker count (6 -> 3) | Step 7 — Broker count optimisation |455| Evaluate MSK Serverless vs provisioned | Step 6 — Serverless fit |456| Optimise EBS storage | Step 8 — EBS storage optimisation |457| Reduce log retention / enable compaction | Step 9 — Retention and compaction |458| Reduce excessive partitions | Step 10 — Partition right-sizing |459| Handle missing data | Step 1 — Validate input |460| Look up pricing / broker types | references/msk-pricing-reference.md |461462## Expert heuristic — the 60-second triage463464The 60-second triage (six checks to run when handed an MSK bill): moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).465If any check hits, deep-dive the corresponding Process step.466467## Pre-flight safety checks (run before any remediation CLI)468469Pre-flight safety checks (confirmation gate, state recording, one-dimension-per-window, post-change verification, blue/green migration, 3-cluster batch limit): moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).470NEVER omit the CONFIRM gate — see FORBIDDEN output patterns above.471472## Verdict semantics473474| Verdict | When to emit | Position in workflow |475|---|---|---|476| `OPPORTUNITY_FOUND` | At least one dimension has a savings-bearing recommendation. | Primary — terminal for actionable findings. |477| `OPTIMIZED` | A change was applied and verified this session; CE line items confirm the new pattern. | Primary — only emitted post-remediation. |478| `ALREADY_OPTIMAL` | All seven dimensions at cost-optimal config AND broker count, retention, and Serverless fit evaluated. | Primary — terminal for healthy findings. |479| `NEED_MORE_INFO` | Data gate failed: CE access denied, CloudWatch window < 14 days, Kafka version unknown. | Pre-decision — emit per-dimension; other dimensions can still emit OPPORTUNITY_FOUND. |480481## Recent AWS features (2024-2026)482483Recent AWS features (2024-2026): moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).484Check before recommending Express tier, KRaft, or the newest broker types.485486## AWS documentation487488Domain: AWS CloudOps / Analytics — Amazon MSK cost optimisation.489490- **Amazon MSK pricing** — https://aws.amazon.com/msk/pricing/491- **MSK Serverless** — https://docs.aws.amazon.com/msk/latest/developerguide/serverless.html492- **MSK broker types** — https://docs.aws.amazon.com/msk/latest/developerguide/msk-create-cluster.html493- **MSK Cluster Tier (Express)** — https://docs.aws.amazon.com/msk/latest/developerguide/supported-broker-types.html494- **MSK with KRaft** — https://docs.aws.amazon.com/msk/latest/developerguide/kraft.html495- **MSK storage** — https://docs.aws.amazon.com/msk/latest/developerguide/msk-storage.html496- **MSK Cluster Linking** — https://docs.aws.amazon.com/msk/latest/developerguide/msk-cluster-linking.html497- **AWS Cost Explorer** — https://docs.aws.amazon.com/cost-management/latest/userguide/ce-what-is.html498- **Well-Architected — Cost Optimization** — https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html499500## References (load on demand)501502- [references/advanced-patterns.md](references/advanced-patterns.md) — Step 0 non-obvious behaviours, quick-start heuristics, cost-structure fundamentals, 60-second triage, recent AWS features (2024-2026).503- [references/diagnostic-commands.md](references/diagnostic-commands.md) — Required data-source commands, Step 1/Step 2 command blocks, pre-flight safety checks.504- [references/worked-examples.md](references/worked-examples.md) — Secondary worked examples (right-sizing, Graviton, Serverless break-even, broker count, EBS, retention, already-optimal).505- [references/msk-pricing-reference.md](references/msk-pricing-reference.md) — Broker-type pricing, Graviton savings matrix, Serverless pricing, EBS and retention cost projections.506507