Recently I came across ESRI web course Update Real-Time Data with Python, and it walks through a tutorial on how to built what is called "feed routine". The idea is basically is to read latest version of certain feature-set from a JSON file shared and accessed through a URL, and feed that into your system, which in this case is a hosted feature layer.
In this blog, I wanted to focus on the function "deployLogic" which takes places after reading the latest JSON data and converting it to ESRI file-geodatabase. This function demonstrate really important workflow on how to update the data of hosted feature layer, while keeping the hosted layer item id - as a Portal for ArcGIS or AGOL item. I didn't find similar workflow explained in the published documentation for ArcPy or API for Python, and I believe it can be accommodated to be used with more complex scenarios.
I will try to summarize the function logic in the following bullets:
Using 7zip sub-process, extract the hosted layer service definition file
Browse to the extracted folder, reach the underlying source file gdb, and delete it
Copy the fresh file-geodatabase that was created in previous step to the extracted service definition folder
Using 7zip, compress the service definition folder into a new service definition file with '.sd' extension, not '.zip'
Using "FeatureLayerCollectionManager" instance, update the hosted layer using the new service definition file
The simplicity of this workflow is that it avoids republishing the service using ArcGIS Pro project, so you won't need to go through something like "getWebLayerSharingDraft" from a Map object, and worry about setting the needed flags "overwriteExistingService", etc.. I find this really easy shortcut, and it will get the job done.