They are interchangeable sometimes.
You can use both เกือบ and แทบ in these sentences.
มาแทบจะไม่ทัน มาเกือบจะไม่ทัน
แทบแย่ เกือบแย่
เหนื่อยแทบแย่ เหนื่อยเกือบตาย
แทบไม่ไหว เกือบไม่ไหว
In these cases, you can't use แทบ instead of เกือบ
เกือบสวย เกือบรวย เกือบไปแล้ว
We always use เกือบ followed by จะ.
I don't think we have the rules for เกือบ and จะ as they have almost the same meaning.