Network Function Virtualization (NFV) is known for its ability to reduce deployment costs and improve the flexibility and scalability of network functions. Due to processing capacity limitations, the infrastructure provider may need to instantiate multiple instances of the same network function. However, most of network functions are stateful, meaning that the instances of the same function need to keep a common state and hence the need for synchronization among them. In this paper, we address this problem with the goal of identifying the optimal synchronization pattern between the instances in order to minimize the synchronization costs and delay. We propose a novel network function named Synchronization Function able to carry out data collection and further minimize these costs. We first mathematically model this problem as an integer linear program that finds the optimal synchronization pattern and the optimal placement and number of synchronization functions that minimize synchronization costs and ensure a bounded synchronization delay. We also put forward three greedy algorithms to cope with large-scale scenarios of the problem, and we explore the possibility to migrate network function instances to further reduce costs. Extensive simulations show that the proposed algorithms efficiently find near-optimal solutions with minimal computation time and provide better results compared to existing solutions.