Kirill Latish
LiveZone
ERP on WebSockets
Problem
The classic WEB Paradigm (known as “pull”)
It has the client (browser) solicit data from the server in a synchronous manner.
This means that every time the client needs a data update, it has to ask the
server expressly to find out if the data has changed and obtain the new value.
Analysis
1. Any user experience consists of two processes: observing and
changing data
2. Browser tab is a perfect universal identifier of the context
3. WebSockets allow to push data to the client (browser)
Technologies
1. WebSocket - Javascript implementation of WebSocket protocol
2. Ratchet - WebSocket server on PHP http://socketo.me
3. Laravel - Best PHP framework
4. Beanstalkd - message queue
5. Redis - in-memory database
Observing
1. Data, that user observes, always can be represented as set of objects
2. Set of observable objects is always less or equal to the set of objects,
that were initiated during the script execution
3. Class and id of the object is enough to identify it, so it is enough to
store two-dimensional array with classes names and ids to fully
describe context
$observableObjects = [
'Class1' => [
'id1' => 1,
'id2' => 1,
],
'Class2' => [
'id3' => 1,
'id4' => 1,
],
];
Changing
1. Data changes, that user makes, can be recorded as sets of object
properties, grouped by class name and id, and action type: “create”,
“update” or “delete”
$changedObjects = [
'Class1' => [
'id1' => [
'acton' => 'create',
'data' => [
'prop1' => 'val1',
]
],
'id2' => [
'acton' => 'update',
'data' => [
'prop1' => 'val1',
]
]
],
'Class2' => [
'id3' => [
'action' => 'delete'
]
]
];
Workflow
Enterprise Scale Example
It was really big:)
Typical problems
1. WebSocket server is daemon - keep it as lightweight as possible.
Need to execute heavy tasks - move them to workers. Otherwise you
will have memory leaks on backend.
2. Always wrap job’s body into try catch, otherwise you will get stuck jobs
3. Don’t forget to restart WebSocket Server and queue worker - it will
help you to avoid a lot if confusion.
4. Be careful with Front-End part! Probability of getting memory leaks
increases at least 10 times when you introduce WebSockets.
Thanks for attention

Кирилл Латыш "ERP on Websockets"

  • 1.
  • 2.
    Problem The classic WEBParadigm (known as “pull”) It has the client (browser) solicit data from the server in a synchronous manner. This means that every time the client needs a data update, it has to ask the server expressly to find out if the data has changed and obtain the new value.
  • 3.
    Analysis 1. Any userexperience consists of two processes: observing and changing data 2. Browser tab is a perfect universal identifier of the context 3. WebSockets allow to push data to the client (browser)
  • 4.
    Technologies 1. WebSocket -Javascript implementation of WebSocket protocol 2. Ratchet - WebSocket server on PHP http://socketo.me 3. Laravel - Best PHP framework 4. Beanstalkd - message queue 5. Redis - in-memory database
  • 5.
    Observing 1. Data, thatuser observes, always can be represented as set of objects 2. Set of observable objects is always less or equal to the set of objects, that were initiated during the script execution 3. Class and id of the object is enough to identify it, so it is enough to store two-dimensional array with classes names and ids to fully describe context $observableObjects = [ 'Class1' => [ 'id1' => 1, 'id2' => 1, ], 'Class2' => [ 'id3' => 1, 'id4' => 1, ], ];
  • 6.
    Changing 1. Data changes,that user makes, can be recorded as sets of object properties, grouped by class name and id, and action type: “create”, “update” or “delete” $changedObjects = [ 'Class1' => [ 'id1' => [ 'acton' => 'create', 'data' => [ 'prop1' => 'val1', ] ], 'id2' => [ 'acton' => 'update', 'data' => [ 'prop1' => 'val1', ] ] ], 'Class2' => [ 'id3' => [ 'action' => 'delete' ] ] ];
  • 7.
  • 8.
  • 9.
  • 10.
    Typical problems 1. WebSocketserver is daemon - keep it as lightweight as possible. Need to execute heavy tasks - move them to workers. Otherwise you will have memory leaks on backend. 2. Always wrap job’s body into try catch, otherwise you will get stuck jobs 3. Don’t forget to restart WebSocket Server and queue worker - it will help you to avoid a lot if confusion. 4. Be careful with Front-End part! Probability of getting memory leaks increases at least 10 times when you introduce WebSockets.
  • 11.