Push vs Poll when large delay
Push vs Poll when large delay
acceptable
Ask Question
All major mobile shops provide their version of a push notification service:
Thanks in advance!
Answer:
Polling is always acceptable when real-time isn't a necessity. What you have to ask yourself
is why would you use one instead of the other?
The purpose of a push service is a couple things; it can be considerably less traffic for you
to deal with if your pushes are broadcasts and a 3rd party provider does the broadcast - this
allows you to send one message and have thousands receive it. But as you note, the
biggest boon of a push service is the realtime nature that allows for immediate updates to
reach your consumers. However when doing pushes you really don't ever want to be
pushing large data sets if you're broadcasting, and you're also at the mercy of the third party
push service you utilize (if you utilize one).
The purpose of a poll is to check for data differences periodically, where the update period
can have an acceptable SLA(service-level agreement ) of inaccuracy up to a certain time
period. A poll will require all your clients to request the data periodically which will mean a
connection being requested for every running client, and the necessity of a live service able
to monitor that data accurately to serve it up to the pollers. Having accurate data to serve up
means some data persistence which will take up disk and maintenance time.
So from this we can see that if you have concerns about network traffic or the maintenance
of a service (which means possibly authenticating/authorizing requests, logging them which
takes up disk space, all the normal requirements of maintaining a service) then you don't
want to force clients to poll. However if the use case requires transmitting a particularly
large data set or you can't be tethered to a third party's API which may change in time as
well as their SLA or charges, then a home grown polling system may be applicable, though
the maintenance overhead may be significantly more. Alternatively you may already be
running service and have the data persisted such that the polling is a light addition to
already in-place infrastructure, which makes polling more desirable.
Though to the central point you make you are correct; if real-time is necessary, polling will
not do. If it is not, then you just have to do the math on how periodic the data can be
checked multiplied by your client base multiplied by your data set size to decide if the
network cost is going to be worth it, or if a push service would be better where you can
always just push a change event that let's them request the large data set in a secondary
step (though atomicity of these steps may be something you need to be careful of
depending on the criticality of the data).
Problem Statemenmt
Currently the application using the polling method (i.e, to retrieve new data
from server in a fixed amount of seconds).
This is quite taxing and does not retrieve latest result immediately. Assuming
the server is using webservice and if possible, without a major overhaul, how
can I better improve on the application efficiency?
By taxing , I mean the server would have to pull up different SQL tables and associated
data and stuff, meaning complex data processing which if there is alot of concurrent users
I'm afraid there might be possible issues with the server performance in the future.
Answer:
The problem with polling is that the observer controls when the call happens yet doesn't
know when state changes so it makes many needless calls. This eats resources especially
when there are many observers. The key to dealing with polling is: as soon as possible, get
the direction of calls going from the point of state change(Suject) to the observer. Then calls
happen when they're needed. Not when they aren't.
Make the server follow the observer pattern. Allow clients to register as observers.
Proxy Pattern:
The proxy could interface to anything: a network connection, a large object in
memory, a file, or some other resource that is expensive or impossible to
duplicate.
In short, a proxy is a wrapper or agent object that is being called by the client to
access the real serving object behind the scenes.
So you can understand that Bank Manager who Approves Bank Loan is real
Object and Executive is Proxy Object which does the validation work before it
promices your loan can be approved by Bank Manager.
To act as substitute for a subject, a proxy must implement the Subject interface.
Clients can't tell whether they work with a subject or its proxy.
See also the UML class and sequence diagram below.
Structure
UML class and sequence diagram
Virtual Proxy
In place of a complex or heavy object, a skeleton representation may be advantageous in some
cases. When an underlying image is huge in size, it may be represented using a virtual proxy
object, loading the real object on demand.
Protection Proxy
A protection proxy might be used to control access to a resource based on access rights.
class ICar {
public:
virtual void DriveCar = 0;
};
public:
ProxyCar (int driver_age) : realCar(new Car), _driver_age(driver_age) {}
~ProxyCar {
delete realCar;
}
void DriveCar {
if (_driver_age > 16)
realCar->DriveCar;
else
std::cout << "Sorry, the driver is too young to drive." << std::endl;
}
};
Output