The experiment table is what makes this land — especially case 2, where the same 2-second lock still delivered five times but dedup cut the side effects to one, versus case 4, where renewing from a free thread got it to one delivery and one side effect. That split between fixing the work and fixing the effects is the part I'd keep. Did the SmallRye bug report get any upstream response yet, or is the workaround still to keep the lock longer than the call?
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
Thanks! Yes, that split between fixing the work and fixing the effects is the main takeaway for me too.
No response from the SmallRye maintainers yet. Since the post I narrowed it down a bit more: a record still counts as "in progress" until its acknowledgement is committed, which can be a second or two after the handler finishes, and the renewal timer can fire in that window. Timeline and details here: github.com/smallrye/smallrye-react...
Until there's a fix, I wouldn't rely on the connector's renewal for slow handlers. Options:
Keep the lock above your worst-case call so renewal never kicks in. The broker caps it at 60 s by default (group.share.max.record.lock.duration.ms, which you can raise on your own cluster), and SmallRye's share-group.unprocessed-record-max-age.ms (also 60 s by default) has to be above the call time too.
Or use the plain share consumer and renew from a thread that isn't doing the work, like case 4.
Either way, keep the side effect idempotent. Sara's lease idea below also helps with the duplicate model calls.
Thank you for narrowing it down further — that ack-commit window, where a record still counts as 'in progress' for a second or two after the handler finishes, is exactly the kind of detail that explains the stray redeliveries. Until the fix lands, keeping the lock above the worst-case call feels like the pragmatic option, since it sidesteps renewal entirely. For a brand-new service, would you go with the plain share consumer and renew from a separate thread, or is the bigger lock the simpler default you'd reach for first?
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
For a new service I'd start with the bigger lock. It has no moving parts: measure the tail of the model call (p99.9, not the average), keep the lock above it with some margin, make the side effects idempotent, and alert on deliveryCount > 1 so you know when the tail grows past it.
I'd only reach for renewal on a separate thread if the calls can run longer than the broker's cap. It works (case 4), but it's more code to get right: the consumer isn't thread-safe, and the renewed record comes back through a later poll, so you have to ack that copy.
If the calls can take minutes, I'd step back and not hold the Kafka lock during the model call at all: write the event to your own work store, ack it right away, and process it with your own lease, a bit like Sara's idea. Kafka stays fast, and the slow part has its own retries.
And an update on the bug: a SmallRye maintainer confirmed it this morning and is working on a fix.
The experiment table is the whole post for me — "5 deliveries, 5 side effects" versus "5 deliveries, 1 side effect" with deduplication makes the real lesson impossible to miss: idempotency fixes the damage, not the wasted work. The model still ran five times, and the tokens still burned.
The part I respect most is the SmallRye finding. Reporting it upstream while the root cause is still unconfirmed, and framing it as "test it in your setup" rather than a verdict, is exactly how a reproducer should be shared. And the thread-safety catch is the trap most teams would walk into: renewal only works from a thread that is free to renew, so the obvious inline poll loop can never renew at all.
One question about the most surprising detail: with a very short lock, even a fast handler was sometimes redelivered. Do you have a suspicion about what is happening there — is the lock clock starting before the handler even receives the record, or is it more like a race between delivery and the first renewal check?
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
Your first guess is right: the clock starts before the handler sees the record. Kafka starts the lock when the broker hands the record to the consumer, and SmallRye seems to time its renewal from then too. With a 2 s lock, the first renewal check comes about 1.5 s after the consumer gets the record.
And your second guess is where I think it actually breaks. A 0.5 s handler usually finishes before that check, and those runs were fine. It only failed sometimes, probably when the handler started late and was still running when renewal kicked in. Every time it failed, I saw the same renewal errors as in the slow case. With a 10 s lock, where renewal never starts, it ran exactly once every time.
So my suspicion is that something goes wrong once renewal starts, and the short lock just makes that more likely to happen with a fast handler. I haven't confirmed exactly what yet; that's what the issue is for.
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
You got me curious, so I measured it. Your second guess was basically right: a record counts as "in progress" until its acknowledgement is committed, which can be 1–2 s after the handler finishes. With a short lock, the renewal timer fires inside that gap, and the same delivery got handed to the handler again. Details and timestamps here: github.com/smallrye/smallrye-react...
Hosted cron job service. Schedule HTTP requests on a cron, after a delay or right away. Every run logged, failed jobs retried, alerts by email or Slack.
What happens on delivery 5 is the part I'd want an alert on. Once the delivery limit is reached the record gets archived and the group moves on, so an agent whose tail latency sits above the lock cap doesn't just do the work five times, it can end up with nothing done and no error anywhere. Graphing delivery count (anything above 1 means a lock expired) gives you warning long before that point. In the 40-second SmallRye run, did any records actually reach the limit, or did it stall before that?
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
Yeah, that's the nasty part. After the 5th delivery the record gets archived and the group just moves on, so you can pay for the work five times and still have nothing to show for it. Alerting on deliveryCount > 1 is a great cheap signal. The handler already gets it (in SmallRye it's on IncomingKafkaRecordMetadata, that's how my reproducer logs it).
To your question: in the 40s run with SmallRye's defaults it stalled before hitting the limit. The first record got handled 2 or 3 times depending on the run, then nothing, and the next record never showed up within 150s. I didn't check what the broker did with that first record afterwards, so I can't tell you if it ended up archived. In the scaled-down runs it did go all the way to 5 sometimes.
Good news though: a SmallRye maintainer confirmed it's a bug this morning and is working on a fix. I'll rerun it once that's out.
The experiment table makes the lesson hard to miss: five deliveries and five side effects without deduplication, five deliveries and one side effect with it. The lock expiring is correct queue behaviour. The damage comes from a model call whose long tail nobody designed for.
Ascendra Ventures ran into the same tension on a candidate pipeline for a seed-stage talent platform, where enrichment depended on long OpenAI batch jobs and callbacks that sometimes went quiet. The requirement we settled on was that every candidate either finishes or visibly fails, and never gets stuck in the middle. The profile processor became a durable workflow: urgent profiles processed immediately, the rest batched, and fallback polling when a callback did not arrive. It reached 99.99% reliability at about $0.004 per candidate imported. The design question underneath was where state lives while a slow call is in flight, which is close to Sara's point about claiming the work before the model starts.
Have you tried keeping the claim outside Kafka entirely, keyed by the business id, and treating the share group only as delivery?
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
Thanks! "Finishes or visibly fails, never stuck in the middle" is a great way to put it.
No, I haven't tried that yet, all my tests keep the work under the Kafka lock. But for long calls it's probably where I'd end up. One thing I'd be careful about: save the claim first, then ack. Otherwise a failed write loses the event for good.
And then you own the stuff Kafka was doing for you, like retries and picking up work from a dead worker. Sounds like your fallback polling covers that part.
The lock-renewal thread-safety catch is a nasty one. One thing I've started doing for slow model calls is claiming the work in the app before the LLM even starts: write a lease keyed by the event or business id with a TTL a bit longer than your p99, and only then call the model. A second delivery just sees the lease and skips, or waits and checks a result store. That cuts the duplicate token spend even when renewal or the framework fails, which your SmallRye case shows can happen. Idempotency on the side effect is still required, but the lease is what stops the five-times-the-cost problem.
I build backend services and APIs with Java, Kotlin, and C#/.NET. My work focuses on system reliability, database performance, integration testing, and security testing of AI agents.
Thanks Sara, that's a really good pattern, and it covers exactly the gap in the table: dedup on the side effect fixes the damage, a claim before the model call fixes the cost.
A few things I'd watch when combining it with share groups, based on what I saw in the tests:
The second delivery shouldn't ACCEPT just because it sees the lease. If the first worker dies after that, the record is gone for good. Releasing it, or waiting on the result store like you said, keeps it recoverable. But every release uses up one of the 5 deliveries, so the lease TTL and the delivery limit have to fit together.
A TTL a bit above p99 still leaves the tail: a call that runs past it lets a second worker start. Extending the lease while the call runs, or a fencing token on the side effect, closes that.
Taking the lease has to be atomic, e.g. a conditional insert or SET NX with an expiry.
In a way it moves lock renewal out of the framework and into your own code, which is the point: you control it and you can test it. I think it's worth adding as a fifth case to the test.
We're a place where coders share, stay up-to-date and grow their careers.
The experiment table is what makes this land — especially case 2, where the same 2-second lock still delivered five times but dedup cut the side effects to one, versus case 4, where renewing from a free thread got it to one delivery and one side effect. That split between fixing the work and fixing the effects is the part I'd keep. Did the SmallRye bug report get any upstream response yet, or is the workaround still to keep the lock longer than the call?
Thanks! Yes, that split between fixing the work and fixing the effects is the main takeaway for me too.
No response from the SmallRye maintainers yet. Since the post I narrowed it down a bit more: a record still counts as "in progress" until its acknowledgement is committed, which can be a second or two after the handler finishes, and the renewal timer can fire in that window. Timeline and details here: github.com/smallrye/smallrye-react...
Until there's a fix, I wouldn't rely on the connector's renewal for slow handlers. Options:
Either way, keep the side effect idempotent. Sara's lease idea below also helps with the duplicate model calls.
Thank you for narrowing it down further — that ack-commit window, where a record still counts as 'in progress' for a second or two after the handler finishes, is exactly the kind of detail that explains the stray redeliveries. Until the fix lands, keeping the lock above the worst-case call feels like the pragmatic option, since it sidesteps renewal entirely. For a brand-new service, would you go with the plain share consumer and renew from a separate thread, or is the bigger lock the simpler default you'd reach for first?
For a new service I'd start with the bigger lock. It has no moving parts: measure the tail of the model call (p99.9, not the average), keep the lock above it with some margin, make the side effects idempotent, and alert on deliveryCount > 1 so you know when the tail grows past it.
I'd only reach for renewal on a separate thread if the calls can run longer than the broker's cap. It works (case 4), but it's more code to get right: the consumer isn't thread-safe, and the renewed record comes back through a later poll, so you have to ack that copy.
If the calls can take minutes, I'd step back and not hold the Kafka lock during the model call at all: write the event to your own work store, ack it right away, and process it with your own lease, a bit like Sara's idea. Kafka stays fast, and the slow part has its own retries.
And an update on the bug: a SmallRye maintainer confirmed it this morning and is working on a fix.
The experiment table is the whole post for me — "5 deliveries, 5 side effects" versus "5 deliveries, 1 side effect" with deduplication makes the real lesson impossible to miss: idempotency fixes the damage, not the wasted work. The model still ran five times, and the tokens still burned.
The part I respect most is the SmallRye finding. Reporting it upstream while the root cause is still unconfirmed, and framing it as "test it in your setup" rather than a verdict, is exactly how a reproducer should be shared. And the thread-safety catch is the trap most teams would walk into: renewal only works from a thread that is free to renew, so the obvious inline poll loop can never renew at all.
One question about the most surprising detail: with a very short lock, even a fast handler was sometimes redelivered. Do you have a suspicion about what is happening there — is the lock clock starting before the handler even receives the record, or is it more like a race between delivery and the first renewal check?
Good question! I think it's a bit of both.
Your first guess is right: the clock starts before the handler sees the record. Kafka starts the lock when the broker hands the record to the consumer, and SmallRye seems to time its renewal from then too. With a 2 s lock, the first renewal check comes about 1.5 s after the consumer gets the record.
And your second guess is where I think it actually breaks. A 0.5 s handler usually finishes before that check, and those runs were fine. It only failed sometimes, probably when the handler started late and was still running when renewal kicked in. Every time it failed, I saw the same renewal errors as in the slow case. With a 10 s lock, where renewal never starts, it ran exactly once every time.
So my suspicion is that something goes wrong once renewal starts, and the short lock just makes that more likely to happen with a fast handler. I haven't confirmed exactly what yet; that's what the issue is for.
You got me curious, so I measured it. Your second guess was basically right: a record counts as "in progress" until its acknowledgement is committed, which can be 1–2 s after the handler finishes. With a short lock, the renewal timer fires inside that gap, and the same delivery got handed to the handler again. Details and timestamps here: github.com/smallrye/smallrye-react...
What happens on delivery 5 is the part I'd want an alert on. Once the delivery limit is reached the record gets archived and the group moves on, so an agent whose tail latency sits above the lock cap doesn't just do the work five times, it can end up with nothing done and no error anywhere. Graphing delivery count (anything above 1 means a lock expired) gives you warning long before that point. In the 40-second SmallRye run, did any records actually reach the limit, or did it stall before that?
Yeah, that's the nasty part. After the 5th delivery the record gets archived and the group just moves on, so you can pay for the work five times and still have nothing to show for it. Alerting on deliveryCount > 1 is a great cheap signal. The handler already gets it (in SmallRye it's on IncomingKafkaRecordMetadata, that's how my reproducer logs it).
To your question: in the 40s run with SmallRye's defaults it stalled before hitting the limit. The first record got handled 2 or 3 times depending on the run, then nothing, and the next record never showed up within 150s. I didn't check what the broker did with that first record afterwards, so I can't tell you if it ended up archived. In the scaled-down runs it did go all the way to 5 sometimes.
Good news though: a SmallRye maintainer confirmed it's a bug this morning and is working on a fix. I'll rerun it once that's out.
The experiment table makes the lesson hard to miss: five deliveries and five side effects without deduplication, five deliveries and one side effect with it. The lock expiring is correct queue behaviour. The damage comes from a model call whose long tail nobody designed for.
Ascendra Ventures ran into the same tension on a candidate pipeline for a seed-stage talent platform, where enrichment depended on long OpenAI batch jobs and callbacks that sometimes went quiet. The requirement we settled on was that every candidate either finishes or visibly fails, and never gets stuck in the middle. The profile processor became a durable workflow: urgent profiles processed immediately, the rest batched, and fallback polling when a callback did not arrive. It reached 99.99% reliability at about $0.004 per candidate imported. The design question underneath was where state lives while a slow call is in flight, which is close to Sara's point about claiming the work before the model starts.
Have you tried keeping the claim outside Kafka entirely, keyed by the business id, and treating the share group only as delivery?
Thanks! "Finishes or visibly fails, never stuck in the middle" is a great way to put it.
No, I haven't tried that yet, all my tests keep the work under the Kafka lock. But for long calls it's probably where I'd end up. One thing I'd be careful about: save the claim first, then ack. Otherwise a failed write loses the event for good.
And then you own the stuff Kafka was doing for you, like retries and picking up work from a dead worker. Sounds like your fallback polling covers that part.
The lock-renewal thread-safety catch is a nasty one. One thing I've started doing for slow model calls is claiming the work in the app before the LLM even starts: write a lease keyed by the event or business id with a TTL a bit longer than your p99, and only then call the model. A second delivery just sees the lease and skips, or waits and checks a result store. That cuts the duplicate token spend even when renewal or the framework fails, which your SmallRye case shows can happen. Idempotency on the side effect is still required, but the lease is what stops the five-times-the-cost problem.
Thanks Sara, that's a really good pattern, and it covers exactly the gap in the table: dedup on the side effect fixes the damage, a claim before the model call fixes the cost.
A few things I'd watch when combining it with share groups, based on what I saw in the tests:
In a way it moves lock renewal out of the framework and into your own code, which is the point: you control it and you can test it. I think it's worth adding as a fifth case to the test.