We introduce an optimal metagrating design for transverse-position metrology in presence of photon shot noise. The proposed working principle is closely related to the formation of a phase vortex in the diffraction orders in the parameter space. Using the topological robustness, we optimize the design and compress all the transverse-position information around a certain point into a small number of detected photons, saturating the shot-noise limit had all the photons used for probing the position been detected. The current scheme avoids the problem of detector saturation in the presence of high probe power while maintaining all the information detected, allowing one to make full use of the high power that is available. Besides, the direct link between the resonant property in the unit cell and the conditions to achieve the bound is given: one with the zeroth dipole resonance and the other one with the anapole condition of the first dipole. The connection between the metagrating design and the optimization using topological robustness along with the fundamental precision limit using classical light gives new insights in all of these fields.