Abstract Farming of houseflies, as well as of other insects, could become a sustainable alternative for producing high-protein animal feed. Although promising, this comes with particular challenges, including monitoring insect health in large-scale farming facilities. In this study, we tested if the expression patterns of immunity-related genes could serve as early diagnostic markers for disease and help prevent infection spread with detrimental effects. We introduced a commonly used bacterial entomopathogen, Bacillus thuringiensis, in the housefly larval substrate and monitored larval biomass changes, pupation, and gene expression of three immunity-related genes: PGRP, defensin, and cecropin. We performed the infection assay for two strains of different geographic origins at two temperatures and with two concentrations of the bacterial inoculum. We found that gene expression was faster in indicating differences between larvae grown in treated and untreated substrate compared to monitoring larval growth and pupation. Most strikingly, although there were no significant effects on larval biomass for 48 hours after the substrate inoculation, the effects on gene expression in some cases manifested already two hours post substrate inoculation. As the two housefly strains showed different response speeds in gene upregulation, there is a need for more frequent routine testing to define which response levels could be considered as an alarm. We conclude that monitoring immunity-related genes and microbial surveys of insect-rearing substrates can be used to diagnose infection and prevent its spread early in mass-rearing settings.