# ML-Empowered Microservice Workload Prediction by Dual-Regularized Matrix Factorization
## 3 Methodology
### Dynamic Detection and Updating  
The dynamic detection and update mechanism ensures the TDDRMF adapts to evolving workload patterns by monitoring prediction accuracy in real time. When the prediction error at a specific time step exceeds a predefined threshold, the mechanism triggers a parameter update, avoiding frequent retraining while maintaining efficiency and robustness. At each prediction step \(t\), the prediction error is computed as  
\[E_{t}=\|Y-\hat{Y}_{t}\|_{F}^{2}, \tag{13}\]  
where \(Y_{t}\) represents the observed workload at time \(t\), and \(\hat{Y}_{t}\) is the predicted workload. If \(E_{t}>\epsilon\), where \(\epsilon\) is a predefined error threshold, the mechanism identifies a significant drift in workload patterns and triggers an update of the model parameters. After triggering the update, TDDRMF first extracts only the most recent \(d\) observation lengths and performs retraining on this local window rather than the entire history to obtain the optimized microservice matrix \(W\), temporal feature matrix \(X\), and error detection parameters \(A\) and \(B\) to minimize the objective function, thereby accelerating convergence and ensuring smooth parameter transition, significantly reducing the computational overhead. The dynamic detection and update mechanism ensures the real-time adaptation to workload changes by focusing updates on significant prediction deviations, thereby maintaining high prediction accuracy without unnecessary computational overhead. Using the low-rank structure of \(W\), it achieves scalability and robustness, even in large-scale microservice systems. This mechanism seamlessly integrates with temporal dynamics modeling and low-rank dependency capturing, providing a cohesive foundation for the framework's overall optimization process. To provide a clear overview of the TDDRMF framework's optimization process, Algorithm 1 summarizes the core steps for parameter optimization and multi-step prediction. ```
0: Historical workload matrix \(Y\), initial parameters \(W_{0},X_{0},A_{0},B_{0}\);Regularization coefficients \(\lambda_{1},\lambda_{2}\), error threshold \(\epsilon\), prediction horizon \(h\), initial error\(\epsilon_{t}\), trend and period parameters \(M,N,m\) and maximum iterations MaxIter. 0: Optimized parameters \(W,X,A,B\); predictions \(\hat{Y}_{T+1:T+h}\). Initialize \(W\gets W_{0},X\gets X_{0},A\gets A_{0},B\gets B_{0}\);  Initialize \(\hat{Y}_{T+1:T+h}\) as an empty matrix. for\(t=T+1\)to\(T+h\)do if\(\epsilon_{t}>\epsilon\)then Step 1: Trigger parameter optimization: for\(i=1\)to MaxIter do  Define the optimization objective: \[\mathcal{L}=\frac{1}{2}\underset{W,X,A,B}{min}\|Y-WX\|_{F}^{2}+\lambda_{1}R_{ \text{AR}}(X|A,B)+\lambda_{2}\|W\|_{*}.\]  Compute gradients: \[\
abla_{W},\
abla_{X},\
abla_{A},\
abla_{B}\leftarrow\frac{\partial\mathcal{L}} {\partial W^{\prime}}\frac{\partial\mathcal{L}}{\partial X^{\prime}},\frac{ \partial\mathcal{L}}{\partial A^{\prime}}\frac{\partial\mathcal{L}}{\partial B}.\]  Update parameters using Adam optimizer: \[W,X,A,B\leftarrow\text{Adam updates}.\] endfor endif Step 2: Update temporal feature vector \(X_{t}\): \[X_{T}=\sum_{h=1}^{M}B_{h}\otimes X_{T-h}+\sum_{l=1}^{N}A_{l}\otimes X_{T-lm}.\] Step 3: Predict workload for the current time step: \[\hat{Y}_{t}=WX_{T}.\]  Store the predicted value \(\hat{Y}_{t}\) in \(\hat{Y}_{T+1:T+h}\). Step 4: Compute prediction error: \[E_{t}=\|Y-\hat{Y}_{t}\|_{F}^{2}.\] endfor return Optimized parameters \(W,X,A,B\) and predictions \(\hat{Y}_{T+1:T+h}\). ```  
**Algorithm 1** TDDRMF framework prediction and dynamic update process. The TDDRMF framework effectively addresses key challenges in dynamic microservice workload prediction through collaborative modular design. To tackle the complexity of temporal dynamics, the framework employs matrix factorization combined with temporal regularization, enabling more accurate modeling across multiple time scales by disentangling short-term trends and periodic patterns.