what's up y'all this is Hussein Nasser from IGeometry where we discuss
software engineering by example and today's topic is true or full
asynchronous service so this is a low advanced topic and at actually at a
following-up video of another video that we made called a a synchronous versus
synchronous client so I do recommend watching that video first to explain
what is the difference between synchronous and asynchronous client from
the client perspective and then come back to this video to how to know how to
build an actual true asynchronous service and we're going to talk about
what is that what is exactly an asynchronous service or true a
synchronous service what are the advantages and all that cool stuff so
stay tuned guys all right if you guys new to my channel obviously consider
subscribing I talked about the software engineering concept by example here and
there's a lot of software engineering I specialize in GIS in general so
geographic information systems so that's my specialty but I'd also talk about
other software engineering topics and journal so if you're interested
subscribe and hit that bill icon to get notified all right and with that let's
get to it all right so let's first explain a synchronous service how it
actually works alright and this allows JavaScript code
that is this is a client itself right so this code lives in the client whereas I
have a service that I have been written someone wrote this service could be
node.js could be wfs let me know first w CF sorry w CF windows communication
foundation so any rest service essentially that what it does it's very
simple it takes a number and it tells you if it's a prime or not obviously
this is a very expensive operation right for not not so much four five and six or
seven but for huge numbers it takes a lot of computation alright so we want to
know so we have author deserves this service
exists there at the back end right so you give it a number using it and it
tells you that hey this is the prime or not true/false very simple right and
we're using a sink a way to make the client asynchronous so this is very
that's that's why I recommend watching that video first to really really learn
what an asynchronous client verses in synchronous client right so yeah we have
an asynchronous client here but the service is still a synchronous right it
still still waits for it all right so yeah it's brunch so that's the function
that function takes a number and this send request makes a get request very
simple and pressing the in equal number and this generator function so waits for
you can still execute a little stuff so the UI is unblocked but after a while
you get that value right but the client stole really doesn't know what's
happening so all he knows all the client knows that hey I send requests I don't
know what's happening right it's just like server's processing this thing it
didn't give me any answer didn't fail right it didn't give me any any failure
so I can try catch and listen to failures but there's no failures there's
no progress I can't know anything about this right you make a request and that's
it you forget about it you wait for it you have to wait essentially wait in a
sense to receive a request from response from the server right you can still do a
UI stuff right but you're waiting you're waiting for a result you can't tell the
user anything about what's happening oh I have processed 50% I for 60% oh I'm
done I'm not done you can't tell how long this is has been done especially
with long processing operations and services this is really critical so
that's the synchronous service that's the classical service that we alright
this is a rest restful service right so you make a request you wait for it then
the server doesn't really tell you anything however you can make your code
little smaller right too and true asynchronous service so what it
does it's it's essentially just little more code at the server level so you
would you introduce and instead of just having the wrist as the rest call as
Prime the function you add another one which is essentially the jobs concept or
or work orders concept of or yeah jobs right so what do you do instead the user
the client will make a request to the service is prime but you immediately the
service immediately returns a job ID he says hey alright I get you I got you
right I got you this number okay I got your request I'm processing it right but
here's a job ID it's like it's like this order confirmation number for for a few
book and travel if you book a hotel or something right do you want to check and
with those guys right so that's this is the same concept essentially so the
server will take that request will start executing that prime job price this is
I'm gonna execute that but there's the job ID number 888 all right and check
with me any any any time I'm gonna tell you more information about that job if
you check with me this is okay how can I check with you there you go you can call
this rest endpoint that's so different at some point slash job / ID give me the
ID and I'll tell you if it's done if it's processing and I'll tell you very
cool information a lot of status I can tell you really cool stuff that about
your job and just just like that this have become really powerful right this
true asynchronous service so that client doesn't have to wait anymore
right you can just close the client if you have the job you can persist it in
the client and then boot the client again and then restore if their job says
hey by the way I just I have this job ID start locally in my in my for Candace's
database name I
anyway the sequel cycle light sorry yeah this and my sequel light I have this job
ID hey server I think I crashed my Chrome has crashed but I have this job
ID is is this job done can you tell me more information about that hey yeah
sure this job has been still processing you requested this job in this date and
this time by this user and it's still processing it's 70% done of the this the
prime number you give the number give me it's a huge so I'm still processing a
lot of stuff so here's the result but but yeah keep
keep checking with me right and you can build the client in a way to to have
this function checked job essentially which is makes the requests and poor
request and it tells you like the progress in this case I just added the
progress and done and you can check that if it's done or not this just
essentially a jason responds which tells you really cool information about the
job and just like that you can build a true asynchronous service all right so
it's sometimes it's really benefit to beneficial to build a true asynchronous
service obviously disadvantages you gotta have ready rel you have to write a
lot more code is it worth it or not do you even have a huge job that executes
at the server sometimes your request is always those like a persistent to the
database and you return right but yeah but with that job with the async rest
you have to maintain a table or database you have to store your job somewhere
right your code has to read those jobs your code has to persist and purge those
jobs after like I don't know 120 days you can't keep your jobs forever if they
are done right disadvantages but I passed this question to you back to you
guys what do you think would you build a true asynchronous service or you were
sticking with a synchronous services because nothing wrong with both right
you can choose win what do you exactly need and a few few have you built every
current servers what is what is your what is your experience with it tell us
in the comment section below and an example of a synchronous server is
actually out joyas server with geoprocessing tools and this is a very
good example where when we use the ArcGIS where is it uses out joyous
service server technology with a true asynchronous service so I hope you
enjoyed this video guys I hope it makes sense and let us know in the comment
section what do you think about this technology or this pattern I'm not at
all called technologists and everything is available there but yeah guys let me
know I hope you enjoyed this video and I'm gonna see you and then mixed one you
guys stay awesome bye bye