Skip to main content

Unlock Your Use Cases: A Deep Dive on Structured Streaming’s New TransformWithState API

Summary

  • Arbitrary stateful operations in Spark: TransformWithState API enables complex business logic in Structured Streaming without manual state management or deep streaming expertise.
  • State management, watermarks, and timers: The API handles state variables, process vs. event time semantics, watermarks, TTL policies, and timer-based triggers for sophisticated stream processing.
  • Production use-case implementation: Real-world examples demonstrate building stateful pipelines for scenarios previously considered too complex for stream processing.

Unlock Your Use Cases: A Deep Dive on Structured Streaming’s New TransformWithState API

Watch: Unlock Your Use Cases: A Deep Dive on Structured Streaming’s New TransformWithState API
Talk by Angela Chu, Lead Solutions Architect, Databricks ; Anish Shrigondekar, Software Engineer, Databricks
Don’t you just hate telling your customers “No”? “No, I can’t get you the data that quickly”, or “No that logic isn’t possible to implement” really aren’t fun to say. But what if you had a tool that would allow you to implement those use cases? What if it was in a technology you were already familiar with — say, Spark Structured Streaming? There is a brand new arbitrary stateful operations API called TransformWithState, and after attending this deep dive you won’t have to say “No” anymore. During this presentation we’ll go through some real-world use cases and build them step-by-step. Everything from state variables, process vs. event time, watermarks, timers, state TTL, and even how you can initialize state with the checkpoint of another stream. Unlock your use cases with the power of Structured Streaming’s TransformWithState!
Here’s more to explore:
Production ready data pipelines for analytics and AI: https://www.databricks.com/solutions/data-engineering
The Big Book of Data Engineering: https://www.databricks.com/resources/ebook/big-book-data-engineering-2nd-edition
See all the product announcements from Data + AI Summit: https://www.databricks.com/events/dataaisummit-2025-announcements

Chapters

FAQs

Why is arbitrary stateful processing difficult in streaming?

Traditional streaming frameworks require manual state management, watermark handling, and complex logic to maintain correctness under late/out-of-order data—TransformWithState abstracts this complexity.

What business logic becomes possible with TransformWithState?

You can implement use cases like session windows, join stateful streams, detect sequences, manage timers, and apply complex state transformations that would require custom code without this API.

How does event-time vs. process-time affect stateful operations?

Event-time processes data based on when it was generated (for analytics consistency), while process-time uses clock time (for latency-sensitive systems)—TransformWithState supports both semantics.

What are state TTLs and how do they prevent unbounded memory growth?

State TTL (time-to-live) automatically expires old state entries, preventing unbounded memory growth in long-running streaming applications with evolving state cardinality.

Full transcript

0:00 Introduction to API

Hello folks. Uh welcome to this session. Uh today we're going to talk about transform with state. Um many of you might have heard of this new API. Um this is the new streaming API that is coming uh along with uh Spark 4. 0 And today uh we're going to do a deep dive into sort of all the various uh features sub features internals of this new API. To give this talk today I'm a software engineer on the streaming query engine team at data bricks.
Uh I'm one of the main contributors for this uh new API and along with me is uh who is one of the lead solutions architects at data bricks um and a streaming expert like she has worked on a bunch of u you know advanced streaming use cases. Uh so she's going to cover this uh presentation along with me. All right. Some mandatory set of slides. Uh you will get a survey. Uh so please uh you know fill this up, give us feedback and we can improve uh content for next year's data AI summit.
Uh as far as the agenda is concerned today, um today we'll talk about like you know uh arbitrary stateful operations in general. Uh this talk kind of assumes that you have some high level background into structured streaming at a high level how it works. Uh what are the basic set of fundamental building blocks and today we'll explore one of the most you know kind of advanced functionality uh that is available as part of the streaming engine uh that allows users to build these you know really advanced uh sort but critical mission uh sort of mission critical operational pipelines.
Uh so we'll talk a little bit of those uh a little bit about those and then um we'll go over a example use case. Uh so we'll explain how you can build an end toend uh stateful pipeline using a sample example and will walk us through uh how to do that with the new transform with state API. Uh and then we'll go over you know some additional set of features that are landing with uh this new API. Uh and then u you know we we'll take we'll spend some time on questions.
All right. So what are arbitrary stateful operations, right? Like so essentially uh structured streaming as you folks might be aware today runs in this uh models known as a microbatch architecture and we have the notion of sources and syncs and we also have the notion of operators and um you know we have uh essentially certain use cases that require us to build uh complex business processing logic. Uh so it's something where you know you you might have to define your own state machine, you might have to return uh define your own pattern recognition logic uh and so on and so forth. uh so for that you know some of the built-in operators that spark provides might not be sufficient.

2:16 Arbitrary stateful concepts

So in order to allow for such uh sort of custom logic uh spark allows you uh to define these uh through what we call as arbitrary stateful operators. Um now these arbitrary stateful operators today or rather before 4. 0 in Apache Spark was basically just the flat map group with state or applying pandas with state APIs. Uh and with the introduction of transform with state uh that is taking it to the next level you know transform with state essentially we'll look to um you know sort of succeed uh flatmap group with state or apply pandas with state uh with the functionality that you can uh implement with this new uh operator. just to go over some of the differences uh between you know these built-in operators and the arbitrary stateful operators.
Essentially you have a few differences uh between these types right like so for built-in operators uh you have aggregations you have stream joins you have drop duplicates drop duplicates within watermark uh the definition of these operators is clearly defined the schema is clearly defined uh what we will emit is clearly defined how we will evict state is clearly defined uh so essentially the user doesn't have to worry about any of these things so for your use cases or for applications pipelines that sort of fit in this category where um you can just rely on the schema and output that is generated by these built-in operators, you know, by all means, you know, you should do that and just continue to use these built-in operators because they are sort of optimized for that specific use case.
Uh but for something that is more advanced uh where you need to sort of you know build some of your own custom logic you want to control how you want to evict state you want to control what you want to emit you you want to control how you want to define state in terms of the schema in terms of the output schema uh in all such use cases uh we now would recommend uh users to move uh towards the transform with state API uh in Apache Spark Another set of clarifications uh because you know people often have uh some questions around these is the notion of time right like so in terms of uh the notion of time we have two uh sort of uh semantics one is around process time and the other uh is around event time.
Uh so process time is sort of you know wall clock based uh it moves ahead irrespective of whether you have data or not. Uh it does not have like the notion of kind of late records or something like that. So essentially you just take in whatever is uh present and it just keeps moving uh along with uh the changes in the wall clock time. Um and if you reprocess data with uh sort of you know different ranges of uh the processing time you might see different results.
Now of course uh in terms of the microbatch architecture for a given batch what you will see will be deterministic because we do record uh the uh processing time uh in the uh offset log. Uh so we also record the uh the watermark as well. uh so for those types of use cases within a batch you will get deterministic results but if you try to process across batches uh using the notion of processing time you might see uh differing output.
Whereas in terms of event time, this is kind of uh a part of your data itself, right? Like essentially you have a time stamp event timestamp column. Uh it is coming through uh your uh set of records like uh for internal row or unsafe row. Um and you want to control how you want to essentially uh you know decide which events are within your window right like you might say that okay this is I won't receive any data after like 3 hours you know since the watermark uh definition uh so I I can choose to sort of u you know uh filter out these late records I can choose to evict and emit the windows uh and so on and so forth uh so event time sort of allows users to perform some of these operations and also because you know how the definition of these events or the event time within these events uh is defined and how they will change you can be rest assured that um the processing will still result in the same set of output even across uh a set of batches.
All right. So with that uh let's move to an example use case and will talk you guys through an end toend use case uh for how to build a sample pipeline with transform with state. All right. Thanks. Everyone able to hear me? Excellent. All right. So we figured the best way to show you how to use this new API is to go through a an actual concrete example and showing the code that was implemented in order to do this example.

7:28 Implementation walkthrough

So here's the use case and uh this is not a real use case. I'm not throwing a customer out here so don't try and guess but this is a common example sparse data and having to forward fill. So the example we'll use here today is an energy company has some offshore oil rigs with sensors that measure the wind speed. These sensors are only going to send data when the value changes. Otherwise there's no point. So all of that data is going to be received and the downstream analysts they want to do five minute averages on these sensor W these sensor readings.
However these five-minute averages they're not going to be consistent if you've got different numbers of readings in each. So what they want is they want to have one measurement per second in each five minute window. You can't do that with the standard windowed operator. It is not going to then fill in blanks in your data. So you need to do that with transform with state and can you put my display back? So this is how to implement transform with state.
What you're going to do here instead of the previous version of arbitrary stateful operations you can implement in an objectoriented manner. So transform with state what you do is you're going to extend the stateful processor abstract class and make a class of your own and with that you're going to extend and implement the abstract methods. There are functions that you need to implement. A couple of these you're going to implement every time and then a few you're only going to implement if you have the usage for them.
The functions you'll implement all the time are init and then you're going to implement I'm sorry, he's moving my display all over the place. And then you're going to implement the handle input rows. If you need to initialize state, you're going to implement that function. And then if you are using timers, you're going to implement handle expired timer. Here's the skeleton for how you implement it in Scola. This is available in both Python and Scala, but with Scala, there's a little bit of a difference.
If you want to initialize state, you're going to be extending an additional class stateful processor within with initial state and that's how you're going to implement the class to initialize your state. But the function names are the same across Python and Scala. So it doesn't matter which one you use, you'll get that same functionality. So now let's start the implementation. I like to talk about arbitrary stateful operations in four steps.
So the first step you're going to need to consider when implementing is you need to define your structures. What goes in, what goes out and what gets saved in between microbatches. So the three types that we need to implement, we do need to implement input, output, state. We'll start with Python. With Python, this is going to look familiar to you. You're still using either the strct type or DDL syntax to define your structures.
We'll start with input and output here. This is going to look very familiar because this is just like the old API. You are going to need to specify output. It's required for Python. For input, you don't have to specify it. I usually stick it in the code just for documentation purposes. Output though does need to be passed into transform with state. So that definition needs to be there. So let's talk about the fun part.
Let's talk about defining your state structures. Previously with the old API, you just had one big state structure. No matter what you needed to put in there, you had to stuff it into one. Now you can actually define very flexible brokenout state in the form of state variables. You can have as many state variables you want. And not only that, you have three different types to choose from. The first type is your value state.
And with a value state, that's going to look familiar to you. It's for defining a value that can be any structure you want. It can be simple or complex. There is also a new type called a list state variable. A list state defines a list of rows. You define the structure of each row. You can get an iterator to go through all of those rows. You can also add to your state variable, an individual row, or another list without having to go pull and replace the entire state variable.
Now the third type is actually my favorite. It's a map state variable and you can store key value pairs in there. You define the structure of the key and you just def define the structure of the value. You can go and get an iterator of the keys, an iterator of the values, the whole map. You can also put in something new by key or pull it by key. You can update it by key and delete it by key. So you suddenly got a whole bunch more flexibility in how you can interact with state rather than just pulling the entire thing out, manipulating it, and putting the whole thing back in.
Another thing with these state variables is time to live. So the built-in operators do something for you. They will evict state after a certain amount of time. If you want to have something similar like that happen for you automatically, you can define a time to live on each of these variables. Now the time to live for the value state variable of course is the time to live for the entire value and when that time is up it will evict for the list state variable that time to live is actually going to apply to each row individually and then for the map state it will be for each key value pair.
One thing to note about time to live duration this is process time duration. So your clock is going to keep running even if the stream stops receiving data for whatever reason. Your clock is going to keep running if your stream is up. So that time to live is still going to apply. If you set it to an hour, then after an hour of clock time, it is going to evict. But if that's useful for your use case, it's available. You don't have to use it.
How you define these structures in Python is in the init function. So in this init function you're going to use either DDL or strruct type again when you're defining the structures of those state variables in our use case. Now let's go to the concrete use case. We're defining two state variables. We're defining a map state variable that's going to have the set of sensor values that we have not emitted yet. And then a value state variable.
There's some things that we need to keep track of between microbatches so we know what we're going to fill next. So we're using a little structure in a value state variable to accomplish that. Now in Scala, I know I skipped over another slide a little rapidly, but in Scola typically you're using case classes, input, output, they both need to be defined for Scala. For state, you can also use these tra these case classes, which makes the code very readable and easy to access.
Now, one thing that's a little bit different about just a data bricks notebook, if you're playing with this, you want to use case classes to define your state structures, you need to put them in a package. This is only for data bricks notebooks. And then you import that package in the same cell that you're defining your extended case, your extended class. Then you can access them in Scala. This is how you declare them.
First, you're going to put in a couple of protected values, one for each state variable. And then in the init function, you're going to finish the declaration. You do have to specify an encoder. So remember a state variable, if you just want to have a single value that's an int, you can put in an int or you can put in a string, and that's totally fine. You don't have to use a case class. You can actually just put in several types, you need to specify an encoder for each one of those.
In order to specify an encoder for a case class, you need to use the product encoder type. Now, for our concrete case, these are the same two variables that I told you about in Python. We're not using time to live. We don't need it. We're very dependent on event time in this case. So, we don't want to have state get evicted for us automatically. We need to control it very explicitly. Let's talk about step two, passing in initial state.
We aren't using that for our use case, but I really wanted to talk to you about this because I like this feature a lot. This is a very simple example that I've got on the screen here. You're just hard- coding a starting value, which can be very useful. But what if you need something more? Wouldn't it be pretty nice if you could take the state from an existing stream and then pull that and use that state to implement an to initialize a new stream.
Now you can in both Python and Scala you can use the state data source reader as part of your code. you go use that state data source reader to pull in a data frame with the state from a previous checkpoint and you can pass that in to initialize a brand new stream. So I wanted to show you a little example of the output of the state reader. That top example there that's an example of the state that is that is stored for a windowed aggregation.
In that case it's the windowed aggregation doing an average and a count below. That's an example of the state stored by transform with state for a map variable. In order to pull the state for transform with state map variable, you do need to specify the v variable name since there can be a bunch of variables in transform with state. But you take that data frame, you manipulate it so that it matches what you want in your new stream and then you can initialize your state.
The key just needs to match your grouping key for your new stream. Now we're on to step three. We've initialized and defined all of our structures. We've potentially initialized our state. Now, this is comes the meat of it. We need to handle input rows. We need to define the logic for when new data is received by the stream. Now, arbitrary stateful operations. You need to think about this a little carefully. When you are defining your logic, you have access to one key.
You don't have access to all of them. You have access to one. You cannot implement logic that depends on information in other grouping keys. So in our case, we're using sensor ID. We're receiving data for multiple sensors. You can't go look at information from another sensor when you're defining your logic. You can't affect the state of another sensor when you're defining your logic. So you have one sensor in your hand and you're going to define grouping logic for it.
So to save time for the next few slides, uh we're only going to have Python. We're not going to put Scala in there, but we do have complete examples of these. They're being put in a public repo uh shortly after the end of data and AI summit. And the link to that repo is at the end of this presentation. So we're just going to have some Python here. This is handle input rows. It can be as short or as long as you want. And what you can see here is the first half of the Python implementation.
And this is the second half. Our function also calls other functions that you implement. You can implement as part of your class that you're extending. So our class is the sensor fill class. We have other functions being called in there. I'm not going to walk through every single piece of this code. That would be pretty boring and too long. Let's talk about the types of things you're going to do in the handle input rows function.
You are going to check the current value of the watermark or the process time. You're going to iterate through new input. You're going to add and remove things from your state variables. You might set or clear timers. And you're going to generate and return output. So we'll look at a few pieces of that for our concrete use case here. So for our use case, with each execution, we are emitting one measurement per second up to and including the watermark value.
That means we need to pull the watermark value. We need to know what it is. The watermark value is going to be the same for every micro batch across all of our keys. So every sensor when it executes this code, it's going to get the same watermark value. So they will all be in sync. You pull that with the timer values object. If you need, you can also pull the current process time, which is going to be the same for the whole microbatch.
It's set once and you can query it as many times as you want in that microbatch. You'll still get the same value. Same with the watermark. Now for our concrete use case, why are we waiting and only emitting records up to and including the watermark but nothing later than the watermark? This is for correctness. We're filling in empty values. We're filling in things that are not present. But if the data was a bit late, we might actually put in a record we weren't supposed to.
A sensor might actually send that. So the only time it is safe for us to emit these records for the downstream aggregator is up to and including the watermark because then we know that any sensor reading we don't have is truly missing and is not going to be sent by a sensor. So this goes to the accuracy of our calculations. This is why for our use case it's important for us to pull that watermark value every time. Next, we are searching through state to find any records that we have from our sensors that we need to emit that are less than the watermark value.
Since the map key is the event timestamp, it's really easy to find out which ones are less than or equal to the watermark value. And we can get an iterator of keys from our map variable to go do that. any of those records are removed by key. So you don't have to do the whole map and added to our output list. So this is Python. Remember that in Python everything's a tupil. Even our keys, it's just a long, but we have to pull it as a single value tupil.
So don't forget that extra parenthesy and hanging comma. Otherwise, you are not going to get the actual value of your key. You're going to get some object that has your key inside of it. There's name tupils defined in our class to make them easy to read. You don't have to use them, but it's something I like to do to just make your code readable. Now, this is the part of the code where we are iterating through new rows.
This is similar to the uh previous API in Python where you need to pull from a Panda's iterator. So, as part of this code, we're iterating through the new rows that were received. Any that are less than the watermark are automatically put into our output list that are going to emit and any that are greater than the watermark are going to be put in state for the next round. Now, you'll notice that I said if I receive any new rows that are less than the watermark, and for folks that are used to dealing with watermarks, you might think I misspoke there or I didn't have enough coffee this morning.
When we implemented multiple stateful operations in Spark structured streaming, there are actually two watermark values in play. You don't see them, you don't notice, you actually don't need to care if you're using the standard staple operators, but you will get a little glimpse of that here, which is why I'm going to explain it now. In your typical, uh, the watermark is calculated at the end of every microbatch and in the next microbatch, we use that value.
Now we're using the value calculated in the previous microbatch and the value calculated in the microbatch before that. There are two. The older one is used to drop late records. The newer one is used to drop state and emit from our standard operators. At the end of the microbatch, a new watermark is calculated and then both those values are updated. So why does this matter to you? because you are going to receive records that are less than the watermark value you're pulling.
When you pull the watermark value from the function that I showed you earlier, you're going to get the later one. You're going to get the one that's used to emit and drop state. So, you can see values come in your input that are less than that watermark value. And that is completely valid for correctness. You're going to want to accept those and use those. The system will still automatically drop late records for you.
So you will not receive late records in this function. But don't be confused if you see records that are less than your watermark appear in this function during your testing. So now the output for this function, this is Python. It needs to be an iterator of Pandanda's data frame. So that's what you need to make at the end. And then for our use case, if a sensor stops emitting data, we still need it to continue filling and emitting sensor readings using the previous known value.
So for our use case, we need to set a timer. And we're going to use that timer if the sensor stops emitting data. Let's talk about timers. This is the fourth step and final step when you are implementing transform of state. But first, we're going to talk about timeouts versus timers. Previously, in the old API, you had to declare a time out. Both timeouts and timers can be process time or event time. But with a timeout, it is only going to fire if nothing is being received by that grouping key.
In this case, it would be for our sensor. But now we have timers. Timers, you can still use them just like timeouts like we're using now. But for timers, you set a time stamp in milliseconds and then the timer will expire. It doesn't matter if new rows are coming in. It doesn't matter if no rows are coming in for that given key. The timer will expire. With a timeout, you can only have one timeout for the entire grouping key specified.
For a timer, you can have as many as you want for a grouping key. In your handle input rows, you can go get your list of timers and do something with them. Maybe there's timers you don't need anymore. Now that you've seen more data, you can delete them. Maybe you want to set multiple timers for the future. You can set them. Timers are very flexible and is going to enable many more use cases than timeouts ever did. In our concrete implementation, it's a little boring because we're using them like a timeout.
But uh I have seen more complex cases where you wanted to interle time out timer. You wanted to go and interle records and have timers expire. You can do that now with transform with state. The order of execution is your handle input rows is going to complete first and then it will execute as many handle expired timer instances it has for each timer that expires. So this is our handle expired timer function. In our case the functionality is pretty similar to our handle input rows.
Um, it doesn't have to check if it's on the first microbatch because if a timer had been set, clearly we've gone faster than farther than that. It doesn't have to check if this is the first time it's seen its sensor because again, a timer wouldn't have been set if we hadn't seen the sensor. And same with state. State will definitely be there. So, the code is a little shorter, but it's still the same. It's going to look through state to see if there's anything older than the watermark.
It's going to generate new records, and it's going to emit them. Now one last thing we'll talk about here in the set of functions you need to create is the close function. This is not commonly used but is put in place for corner cases. This is actually for cleanup on executives. This is not something that is going to execute every time a microbatch fires necessarily. It's not doing it per grouping key. So example of this that actually we did run into is that there was a local file read that got opened and then the close function needed to actually close that reader later on each exeutor and so that was put in the close function but normally y'all aren't going to use this one.
So now let's put it all together. How do we call this thing? So this is the example of how to call transform with state in pandas. You can see that we actually put in a custom argument into our class. Since we defined it, we can do it. We put in a window minutes argument. The reason we did that is I was setting timer values based on which five minute aggregation we happen to be working on. And I knew that because of the watermark.
I just didn't know how long the window was. So I put in five minute windows. This class could be reused for 10, 15, 20 minute windows just by changing the argument. will just keep up with the existing windowed aggregation. Now, if you're going to chain with additional stateful operators, you have to specify the event time column name. So, you can see that down there at the bottom. That is what the downstream operators are going to use to check against the watermark.
That's the column it'll use. So, you need to tit that information. If you're not downstream chaining, if you're not calling something else, you don't need to specify that. This is the example in Scala. You're going to call transform with state instead of transform with state in pandas. And then the syntax is just a little bit different. If you're chaining operators, you're still going to include that column, but you don't have to specify the time mode.
It's going to infer the time mode to be event time. If you're not chaining, then you need to specify the event time. And you can use either event or process just like typical. So here are the results from transform with state. This is an example output of the code that we ran. There's one measurement per every second. I also added some flags in there just to make the results interesting. You can see what was generated.
You can see when it was just keeping up with the watermark with those flags there. And you can see by the rounded time stamp there is one measurement per second. And the value will change when we get an actual measurement from a sensor. So I wanted to review really quickly. I didn't tell you guys there would be a quiz. The first thing you end up doing when you need to implement arbitrary stateful operations in general, the first thing is you have to define your structures.
Input, output, and state. What's the second thing you need to do? Do you need to initialize your state? If so, you need to code that. The third and most important thing you need to do is handle new data. And you do that by implementing handle input rows. The fourth thing, are you going to use timers? And if so, you need to define your logic for handling expired timers. So now let's finish our use case because just filling in the uh the sensor data was not the only thing we needed to do.
We needed to get the fiveminute average. So we just pass it into the standard built-in window function. I've had to implement a window function by hand, actually, and it's kind of annoying. We've got this handy built-in function that'll do it for you. So, we pass all those values into the standard windowed function. It's going to aggregate the results of the transform with state or transform with state and pandas call.
You do not need a second stream. You do all this in one stream. Clearly, a sensor reading every second is going to be very chatty. It's going to be very large. We don't need to store any of that in an intermediate table to get these five minute windowed aggregations. We can just do all of this on the fly and don't need to retain that. So we can save a lot of storage. We can save time and it's only one string. This is available in both Python and Scala this chaining mechanism.
And finally here's the output for our finished use case. Implemented the average and then also implemented a count so that we could validate that there is exactly one measurement per second in each five minute window. So if this all sounds good to you, we aren't actually done talking to you about transform with state features. I couldn't get every single feature into our concrete example and there are some really good ones.
So I'm going to pass it back to who's going to talk to you about some of our favorite things. Awesome. Thanks uh for walking us through that use case. Uh as mentioned that is not the only set of things that come with transform with state. Uh you can define state variables you can add or remove them within the same pipeline within the same checkpoint. We don't force you to create a new checkpoint. Uh you can define TTL as you need.

32:08 Advanced features

Uh currently this is only supported for processing time. Uh but it'll take care of eviction for you. So for your GDPR compliance use cases, you don't need to worry about uh evicting uh the state. uh you can initialize any data frame from any source whether it's from delta whether it's from an existing checkpoint whether it's from some other batch data frame you can use that for state in initialization uh timers in both uh event time and processing time uh and you can get like you know granularity of expiration um operator chaining as she mentioned uh and then along with that are a couple of new features additional features uh for schema evolution and subsecond latency uh for schema evolution Uh essentially as many of you might be aware once you define the state schema uh and if you want to make changes like you know you want to add columns remove columns uh do type widening uh those uh types of uh features are not supported and you would have to essentially start your uh streaming query from a new checkpoint.
Uh so with the introduction of transform with state and with 4. 0 So uh Spark will now support uh additional encoding formats uh which will allow you to perform the schema evolution for your existing pipelines without uh tearing down anything and just uh you know adding and removing fields as it as needed. All right. So um the way you actually enable uh schema evolution is just by changing the encoding format to avo.
Uh if you do this then we will perform all the schema validation checks uh for you. Uh we'll make sure that the changes that you define in terms of the state schema for any state variable type whether it's value state, list state, map state are compatible with uh the type of uh changes or operations that you want to perform. Uh we will manage all the metadata for you. Uh none of these are doing full scans of the database uh or the Rox DB that we use uh as the underlying state provider.
Uh so essentially we just keep track of the updates. We use the old schemas, new schemas to make all the reading and writing efficient uh for users. Uh and all of these uh sort of functions and functionality are backed by a lot of improvements and enhancements on the core engine side. We have secondary indexes, we have new uh range encoders, uh we have key schema encoders. So all these kind of you know improve the performance significantly um for the new transform with state API. uh and we allow for model evolution like the state model evolution at the state variable level as well as uh for uh what uh items you want to define within your individual state variable types as well.
And uh if you folks want to go even lower with really low ultra low latency uh where the end to end latency for records uh that we're seeing is you know in the range of like 100 to 200 milliseconds or even lower than that in some cases uh spark with spark we are now introducing realtime mode and realtime mode will work uh along with transform with state uh and you can define all of your stateful logic as you need. uh we will ensure that you can do efficient rowby row processing.
Uh we ensure that uh you get you can define any number of timers and that they will fire with uh the fastest or the lowest uh latency as as much as possible. Uh we'll support uh efficient uh TTL mechanisms. Uh so you can now get you know really low latency for even stateful streaming pipelines uh with Spark. All right. So in terms of availability uh transform state uh is available with DBR from 16. 2 onwards. Uh we've initially added support for assigned clusters or like dedicated clusters uh for Scala and Python.

35:58 Availability and wrap-up

Uh we are also adding support for shared clusters. The uh support for shared clusters with Python is already available with the uh data bricks 16. 3 release. Uh and we will soon add support uh for shared clusters in Scala as well. and of course uh subsequently with DT uh DT shared and uh DT serverless uh as well. Uh all the changes are available with Apache Spark 4. 0. Uh if you guys want to try out uh sample pipelines uh there are a bunch of resources out there.
We've linked a few uh set of blogs here. There are external blogs that folks have published. Uh and in terms of adoption, we continue to see strong adoption. like it's just been a few months but we've already had u numerous customers who have run like thousands of pipelines using the new transformer state operator uh within data bricks already. All right. So with that uh we will conclude uh the session in terms of the material that we had.
Uh but I know that we've covered like a lot of content. So if folks have any questions uh anything uh that's on your mind u anything that you would like to ask feel free and we can we can answer some of those.

Learn more about the Databricks Data and AI platform.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.