Unfortunately, different foods are digested at different rates. However, our insulin works at one rate.
Therefore, the glucose from some foods may reach out blood before the insulin has started to work.
Some people overcome this by pre-bolusing. Depending on the person and the type of food they are eating and the insulin they are taking, this pre-bolus may need to be 45 minutes before eating.
This could be a challenge if you do not know what you are going to eat.
On way around this is to do multiple boluses - one pre-bolus which covers some of what you will eat and another once you have eaten.
Another may be to consider a different insulin. For example, Fiasp works faster for some people ... but does not work very well for others.