Create middleware that pushes analytics into an MPSC channel, that is processed in batch and stored in the local database. https://github.com/antifuchs/governor for rate limiting. Column for hits, column for timestamp, each batch records number of hits at the given timestamp.
Pre-built solutions:
Home-made: