Counting records with changing stages


Hello All,

I have a scenario in which i am getting records from users like -:


So the records are coming in a stream which i am getting from kafka.

The scenario is like 1st record i get is like-:


again if the record is updated then it is pushed again in kafka and i get-:


So what i need to do is i need to count the records in the basis of stages and if a particular record moves from 1 stage to other then that stage should reflect 1 less record and other stage would be reflecting 1 more record.

Kindly help on this.

Till now i have seen spark structured streaming and which seems to solve the above problem. So is there anything else which can solve the above scenario.