ݺߣ

ݺߣShare a Scribd company logo
Immortal system
as a piece of cake
By Nickolay Tsyb
Javameetup
My experience
Commerce software development over 8 years
My experience
Now Im working in HYS-Enterprise as a teamlead
My experience
My experience
My experience
My experience
Hillel coaching
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Call center
Call center
Call center
Call center
Starting Waiting Talking On hold Finishing
Starting Waiting Talking On hold Finishing
Starting Waiting Talking On hold Finishing
Handling
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Zero downtime deployment
Zero downtime deployment
Fault-tolerance
FINITE STATE MACHINE
Chapter 1
What is finite state machine?
Chapter 2
How to build fault tolerance system?
Chapter 3
Deep dive into spring state machine
Abstract mathematical model
or
graph with states and transitions
Finite-state machine
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Examples from real life...
Conveyor manufacturing
AI in computer games
Animal behavior
Example: coin-operated turnstile
Example: coin-operated turnstile
States
1. Locked
2. Unlocked
Transitions
1. Push ( -> )
2. Push ( -> )
3. Coin ( -> )
4. Coin ( -> )
States handling
void coin(State state) {
...
if (state.equals(LOCKED)) {
//coin implementation
state = UNLOCKED;
}
...
}
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
States handling
void push(State state) {
...
if (state.equals(UNLOCKED)) {
//push implementation
state = LOCKED;
}
...
}
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
What about real project?
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
How can we just handle new state in project?
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
One of the main problems
Coupling
business logic
states handling
Complexity increasing
Hard-readable code
High barrier to entry for new members of
team
More time for testing
What could we do?
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Decoupling
business logic states handling
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Spring state machine
Spring state machine
<dependency>
<groupId>org.springframework.statemachine</groupId>
<artifactId>spring-statemachine-core</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
Sitting
Eating
Sleeping
Transitions configuration
Sitting
Eating
Sleeping
Actions configuration
Sitting
Eating
Sleeping
meow...
Guards configuration
Sitting
Eating
Sleeping
meow...
Is hungry?
Support of extended state
Sitting
Eating
Sleeping
meow...
Is hungry?
Support of internal state machine
Sitting
Eating
meow...
Is hungry?
Listener
Sitting
Eating
meow...
Is hungry?
Persisting
Sitting
Eating
meow...
Is hungry?
Error handling and testing
Code example
public enum States {
SITTING,
EATING,
SLEEPING;
}
public enum Events {
SIT,
EAT,
SLEEP;
}
public void configure(StateMachineStateConfigurer<States, Events> states) throws Exception {
states.withStates()
.initial(States.SITTING)
.state(States.EATING)
.end(States.SLEEPING);
}
public void configure(StateMachineTransitionConfigurer<States, Events> transitions) throws Exception {
transitions
.withExternal().source(States.SITTING).target(States.EATING).event(Events.EAT).and()
.withExternal().source(States.EATING).target(States.SITTING).event(Events.SIT).and()
.withExternal().source(States.SITTING).target(States.SLEEPING).event(Events.SLEEP).and()
.withExternal().source(States.EATING).target(States.SLEEPING).event(Events.SLEEP);
}
Data storage and persisting
Data storages
States persisting
Events
States
Transitions
States persisting
Events
States
Transitions
Intercept and update
State
machine
context
State machine context
State
machine
context
Serialization
(Cryo by default)
Redis
Mongo
JPA
Add or update
State machine context
State
machine
context
Deserialization
(Cryo by default)
Redis
Mongo
JPA
Restore
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Immortality
(fault-tolerance)
Master-slave
SLAVE
Requests
MASTER
MASTER
Master-slave
Requests
SLAVE
Master-slave
Master
Requests
SLAVE
MASTERM
ASTER
Master-slave
Master
Requests
MASTER
Master-slave
Requests
MASTER
Master-slave
Requests
MASTER
SLAVE
Deployment
procedure
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Build&Deployment process
Push
Build&Deployment process
Push Trigger (pull&build)
Build&Deployment process
Push Trigger (pull&build)
Create and store image
Build&Deployment process
Push Trigger (pull&build)
Create and store image
Get image
Build&Deployment process
Push Trigger (pull&build)
Create and store image
Get image
Deploy
Build&Deployment process
Push Trigger (pull&build)
Create and store image
Get image
Deploy
Conclusions
Conclusions
Conclusions
Useful links
Quick start
Useful links
Documentation
Useful links
GitHub
Contacts
Thank you for
your attention!
Any Questions?

More Related Content

Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."