Viscous flow around two spherical macroscopic cavities (or void spaces) in a granular material, which is exposed to an otherwise uniform flow at infinity, is investigated. The flow field is obtained analytically by solving the Stokes equation inside and the Darcy–Brinkman equation outside of the cavities, where continuity of the velocity and that of the stress are assumed on the boundary. In our previous complementary paper (Sano, Karmakar & Sekhar, J. Fluid Mech., vol. 931, 2022, A20), we obtain that two cavities of equal size in a tandem position are more prone to collapse for a shorter centre-to-centre distance with low permeability. In the present study, the asymptotic analysis of the interaction of two spherical cavities of different sizes with arbitrary configuration is presented. Particular attention is paid to the configuration dependence of two cavities of equal radius. The velocity field and the volume flux into respective cavities are calculated, which reveal that two cavities with orientation less than a certain critical angle are given a larger volume flux and are more prone to collapse. The present results are applicable to predicting the behaviour in a fixed-bed regime of a solid–gas transport system, microscale waterway formation in a granular material, onset of landslides, collapse of cliffs and river banks, etc.