I have done iot solution using golang, kafka, grpc, nodejs, postgresql and mysql. Logs normally inserted using guid PK thus we need 2 tables. Both tables contain exact structure but device log table has serial pk. When new payload arrived, insert new data into log table while patch / update data on the device log table. This is a must especially for PostgreSQL. For better performance, the log table pk can be big serial too as the max value will reach maximum after 58k years if 5000 devices reporting at every second interval. Finally, the latest device event can be queried from device log table which has only 5000 rows instead of millions of rows. To speed everything, sometimes, we need something like in memory cache for those 5000 rows as pulling data from database while inserting and updating makes everything slow. Looking to work for you. Thanks.