Why does the Ticket ID keep resetting?

Why does the Ticket ID keep resetting?

Are there any limitations or is there a lifespan on generating a TicketId? I am in the middle of programming an API interface and have found that every so often I will have to re-request a Ticket_ID for a user.

You can imagine how cumbersome this is and even more importantly see how programs will break if this continues to happen.

Does anyone have an explanation or perhaps a workaround to the problem?