Notifications to inactive users


I got little consideration: how to approach (what conditions should be met for example) to send notification only to users which are not right now in our app? It will be stupid to send it all time as for example user is in chat page and also receiving notifications.

One scenario is to check user activity every 5 second for example, and when lastActiveTime > 1min send notification. I thinking if in app will be for example 5k users at the same time it wont slow down the app?

Any good practice about it?