There’s some overlap between this post and others, but I’ll try to fix a few things myself here.
Why are there two types of connections: outgoing and incoming?
At the risk of stating the obvious, we sometimes ask our nodes to connect to other nodes (overboard) In other cases, the node is our node (inbound). In a healthy peer to peer (P2P) protocol, it is virtually impossible to avoid both outgoing and incoming requests occurring. A more interesting question is the extent to which outbound and inbound connections are handled differently across nodes. The Bitcoin Core PR Review Club Note (June 8, 2022) on inbound block relay-only connections states:
Once a connection is established, the relationship is largely symmetric (the protocol works identically in both directions). However, we have some preference for outbound peers.
If you’re concerned about malicious full nodes, there may be trusted or semi-trusted full nodes that choose to connect (outbound), but probably all inbound connection requests will come from nodes you barely know about.
Is the outgoing connection the one announcing the new block/transaction, and the incoming connection the one announcing the new block/transaction?
No, both outbound and inbound connections can notify nodes of new blocks and transactions, and vice versa. The PR review club I mentioned discusses block-relay-only peers, which decide to relay blocks only to specific peers rather than transactions or IP addresses. Inbound connections may also indicate that you do not want to receive transactions, etc.
When you want to do an initial synchronization (IBD) or ask something completely random about a block or a transaction or some third thing, is it done with an outgoing connection or with an incoming connection?
both. If the peer/connection is not recognized at IBD startup (i.e. there is no connection at all), you may need to leverage DNS seeds to discover potential peers.