what exactly does the Gmail API push notification rate limit mean? - gmail-api

I'm building a messaging system for GCP-hosted platform and plan to use Gmail as a backing system. Users can write their messages through our system which will invoke Gmail API to send emails to other recipients. When someone responds, Gmail API sends a push notification and our system in turn notifies a used.
As I expect high spikes of user activity, the limitation of 1 notification per second (https://developers.google.com/gmail/api/guides/push):
Each Gmail user being watched has a maximum notification rate of 1 event/sec. Any user notifications above that rate will be dropped.
doesn't seem to work for me. But to be sure I want to understand what does it exactly mean.
In particular:
what will happen if my mailbox receive 100 emails in a second? Will Gmail generate a single notification which will include all 100 messages? Or there will be several notifications generated which will eventually notify me about all messages? Or due to high messages rate and the above-mentioned limit of 1 notification per second I will receive a single notification for the first message and the rest 99 will not be pushed to my backend?

What the documentation tells you is that, if 100 notifications appear on the same user on gmail at the same time, the first notification would come thru, then the other 99 would be dropped.
However, there is a way to recover changes by using history events, this is referred to as sync and there are multiple ways to do this. I suggest you read up on the Partial Synchronization guide.
The documentation also offers some advice on how you should architect your code to deal with this, specially in the Reliability section of the documentation.

Related

how could i identify that alexa notification is being seen(heard) by the user?

I want to push notifications to my Alexa Device until the recent notification is seen by the user. If the user has seen the notification I should stop sending it. If the customer hasn't seen my recent notification I should keep on sending the notifications until they have seen it.
So I need to identify whether my notification has been seen by the user or not.
Is there any service or API that could fetch me whether the delivered notification is seen by the user or not?
As far as I know, Proactive Events are one-way and not bidirectional: you send a notification to the user, the user can read it but there is no way to know if the user has read the notification.

Persistent Group using XMPP

I am using XMPP and MUC for creating a group and it works fine till the user is online. The user leaves the group as soon as he goes offline. I want a user to stay in the room when he is offline and receive the unseen messages when he comes back. How to achieve this in XMPP. And how to create group and add users dynamically.
Can i make the user online all the time..is it is a good approach.? if so then how can i do this - making user online all the time
XMPP MUC is based on user presence. A new upcoming protocol address this issue. It is called MIX: https://xmpp.org/extensions/xep-0369.html
It is still preliminary, but you can expect fast iterations and improvements.

Synchronizing Clients with Gmail

What is Synchronizing client with gmail ? Can anybody give a detailed explanation, because i want to have a better understanding over this concept.
For example, if your client keeps any local cache of the Gmail mailbox data like the Message.Id and labels, or headers, or the entire email. Then in order to update your client you're synchronizing it with Gmail--pulling new updates down to your client. In cases of clients designed for offline use, then synchronizing may also mean pushing local updates back up to the server (e.g. label updates made by client while "offline" that get applied at some later point). That's the general definition of synchronizing.
For the Gmail API specific case, Gmail has a backend mailbox-wide history Id. Any change that affects that account in any way gets a history identifier and most (but not all) history changes affect the state of email messages. Like adding a new message, changing the labels on a message, or deleting a message. Clients of the Gmail API can poll the history Id and find out what's changed since the last time they synchronized and pull down updates to maintain their sync.

How does Trello show users online/offline/idle state accurately?

Trello shows the information of online/offline/idle status very accurately as I personally saw. There are several solutions for tracking users online statuses, and to do so accurately requires a serious overhead. There are also the traditional problems of not knowing if a user closed the browser, disconnected etc. that cause inaccuracy in showing the offline/idle status. For a platform that does not have chat functionality (which, I believe, which would have taken the overhead of tracking users' status and therefore makes the task finally easy) how is Trello achieving this, albeit without much overhead?
Also Trello is able to detect disconnects and resume connection (not so smoothly though).
The Pushing and Polling layer of Trello is described here
Each browser tab is considered to be a session, associated with one user. Each session's activity level is tracked separately, with a user being shown with the highest activity level of all of its sessions (where active is highest, then idle, then disconnected).
Each tab periodically sends its current status to the server - every minute if it has a working WebSocket, every 5 minutes otherwise. Current status is reset to active every time the tab gains focus, or there is a keydown or mousedown event. It goes idle if it has been more than 5 minutes since the most recent of those events. The tab sends a status of disconnected in the onunload event, but we don't depend on this.
Every time a session sends its status to the server, the server looks at all of that user's sessions to determine whether that indicates a change to the user's status. If it does, it broadcasts that new status to every person watching every board that user is on (this goes through the same framework that the rest of Trello's instant updates go through, and is too complicated to explain here).
The server also checks each session to see if its been too long since we've heard from that session (2 minutes if its a WebSocket session, 10 minutes otherwise) and removes the session if it has been (removing a session indicates it is disconnected).
There are a couple of optimizations hiding in there, but that's the main story.
Trello using socket.io.. so when ever a user login it broadcast a message that user has logged in , then they show him as online.
Once he disconnects they send a message on socket again to show him offline.
Many realtime apps using socket.io for showing realtime activities.

Handling Transaction Between Paypal and Local Datasase

What is the best practice to handle transaction between application and paypal.
Consider:
I'm Alice and I want send money to Bob
In my DB I see that Bob has $200 and I want to send him $150.
Once transaction is sent I want to update the Bob's account such that it would contain $50.
Now according to PayPal API I can send Pay and receive success. However what happens
if I for example send Pay it succeeds but I fail to receive a response due to network problem. So I assume that error happened and try again and technically I'll send $300 to Bob instead of $150?
How can I handle such a transaction - between a local database that keeps an account and the remote PayPal API?
I had this exact concern recently with an ASP.NET MVC project I was completing for a client.
I learned two things:
Communication between Paypal and your database cannot be trusted (well, didn't really learn this, but it was entirely reinforced)
I now understand why so many websites that have Paypal as a transaction type mention there could be a processing period between the time that the transaction was completed and shipping/delivery of the product is completed.
The way you handle the situation is similar to the way a business could handle personal checks:
A personal check looks like currency (and typically is), but many businesses would like some sort of verification from the bank that funds are available before they accept payment - so they use a machine that asks the bank if funds are actually available.
If the machine says the funds are available, the business trusts it and you complete the transaction. However, the machine can give an error message that typically means "the funds are not available or something went wrong" and the business has a decision to make:
We can trust the customer and accept the check, deliver the product, and hope for the best when later depositing the check to the bank.
Or we can tell the customer that it will take time for the check to clear, deposit the check, wait for the funds to actually arrive in our account, and (if successful) deliver the product after the business receives funding.
This sounds inefficient with the way many businesses operate today, but it is something that does come up. In fact, this is why a lot of businesses stray away from accepting personal checks, they are unreliable when compared to other methods of payment.
Now how does this correlate to handling a Paypal payment?
A Paypal payment looks like currency (and it typically is), but many businesses would like some sort of verification from the Paypal that funds are available before they accept payment - so they use Paypal PDT, IPN, or other method for checking that the transaction was handled appropriately.
If Paypal properly responds to one of the verification requests, the business can trust it and complete the transaction. However, your website may throw an error of some sort (i.e. Paypal could reply with an IPN response of NOTVALID, or you could never get a reply from Paypal). The business has a decision to make:
The business can trust the customer and accept that they have made a Paypal payment and everything should be alright (very bad decision in the case of a Paypal transaction)
Or the business can tell the customer at check-out time that there may be a 72 hour processing period for Paypal payments.
This may not sound like the best way to operate your business, but it is the way we have to deal with an imperfect internet.
I would set up the Paypal payment flow similar to this:
UserA wants to send $100 to another UserB using Paypal
UserA enters the value in the 'checkout field' and is sent over to Paypal to verify the transaction.
UserA is sent back to your website from Paypal and your website performs the IPN check with the details that Paypal has POSTed to your site(I chose IPN in this case - as if we were using Express Checkout as opposed to some other payment gateway that Paypal offers).
If the IPN is VALID, process the transaction as expected.
If the IPN is not VALID, mention to the customer that there may be a delay in processing, have your application send you a notification that a possible Paypal transaction issue has occurred (you may want to include a reference id so that you can quickly find which transaction this notification is referencing), and mark the transaction as pending as opposed to complete or something similar.
An admin of the site who handles these notifications will manually investigate the transaction (or force the website to check with Paypal again - see the Paypal API documentation for details on this) and manually mark the transaction as complete or failed.
Notify those involved of the status of the transaction.
It is annoying that we have to have extra steps involved to make sure the money was transferred, but, as mentioned earlier, we are using an imperfect system and we want to be very certain of the success / failure of financial transactions.
An added bonus to this process is that there is likely to be notifications when someone is tampering with the Paypal payment system - leaving you better equipped to deal with evil-doers in the future.
Please refer this link ,Hope PayPal Authorization & Capture method will be suitable for you ,since you don't want lose the response as well as miscalculated amount transfers, PayPal provides correlation id that can be referred for PayPal to confirm your order status,it will be better to pass the order id to PayPal API.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_admin_authcapture
http://www.scribd.com/doc/6303345/40/CorrelationID-for-Reporting-Problems-to-PayPal
Good Luck!
This is known as 2-phase commit. As long as paypal does not participate in the same transaction, you will run into problems.
I would debit Alice the $150 and reflect the transaction is "Pending Confirmation", then periodically poll PayPal to synchronize your DB, since you have no control of when the network or PayPal may be available, post, reverse or adjust the transaction. Once PayPal processes the transaction, you can change the status in your DB from "Pending" to "Completed". BTW, this how bank accounts and credit cards are processed. You could apply a double-entry accounting method to your DB. (see this Q&A)
From what i see you need to make sure the transaction is complete otherwise nothing should be done .
If you deposit the money into PayPal API and you do not receive an response from PAYPAL API then you need to rollback the transaction in you DB.

Resources